• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

689
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

almost 3 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]);
  }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error