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

255
Views
submit PDF file with formData in react

I am having problems with formData to submit a pdf file

const [file,setFile] = useState()
const [isFilePicked, setIsFilePicked] = useState(false);

having an input type file

<input  accept=".pdf" type="file" onChange={uploadFile}/>

and then the onChange function

    const uploadImage = async (e) =>{
  console.log(e.target.files[0])
  setFile(e.target.files[0])
  e.target.files[0] && setIsFilePicked(true);
  }

At the end when I want to submit I got "FormData{}"

const post = async () => {
    const formData = new FormData();
    formData.append('File',file);
    console.log(formData)
}

why am I getting this???

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

0

The FormData interface doesn't store the appended key value pairs directly into itself so logging the FormData itself won't output anything. Don't worry, the files are "stored" in the FormData nonetheless. To get the console.log() to log the files for you, you have to get the files out of the FormData first. One way is to get the iterator of FormData and then transforming it into object. Example:

Object.fromEntries(formData.entries()) // will result in { "File": <your file> }

so in case of your code snippet you can do as follows:

const post = async () => {
  const formData = new FormData();
  formData.append('File',file);
  console.log(Object.fromEntries(formData.entries()))
}
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!