Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

865
Views
FormData append not working, its showing empty object

I am trying to convert data into formdata. As you can see here upto input of onSubmit, the data is showing fine, But, I tried it to append as formData, but its not working.

const onSubmit = async (input) => {
    console.log("input >>", input);
    const formData = formHelper.getFormData(input);
    console.log("formData >>", formData);
    // submitAction(formData, setError);
};

formHelper.js

const getFormData = (object) =>
    Object.keys(object).reduce((formData, key) => {
        if (object[key] instanceof File) {
            formData.append(key, object[key][0]);
        } else {
            formData.append(key, object[key]);
        }
        return formData;
    }, new FormData());


const formHelper = {
    getFormData,
};

export default formHelper;

And, here is the screenshot of the console.log. enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When logging a formData object with just console.log(formData) it always returns empty, as you can't log formData. If you just have to log it before sending it, you can use entries() to get the entries in the formData object, like this:

 for (var key of formData.entries()) {
      console.log(key[0] + ", " + key[1]);
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!