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

96
Views
why i cant upload file in reactjs

My file is shown in the console but getting a 400 error i.e. Please upload the file.

    function AdminPanel() {
      const [show, setShow] = useState(false);
      const [pdffile, setPdffile] = useState("");

   function handleFileChange(e) {
      const files = e.target.files[0];
       setPdffile(files);
       console.log("Guru4666", pdffile);
   }
  const SubmitPDF = () => {
     axios({
     method: "post",
     url: "url",
     data: {"dataFile" : pdffile }
  }).then(res => {
    console.log("REs", res)
  })
}

<div className="form-group form_aside">
    <input type="file" className="form-control" id="files"
     name="PDF" onChange={handleFileChange} />
</div>
                          
Submit

Console result is

Guru4666 
File {
lastModified: 1634196746000
lastModifiedDate: Thu Oct 14 2021 13:02:26 
GMT+0530 (India Standard Time) {}
name: "barkelou.png"size: 5906type: 
"image/png"webkitRelativePath: ""
[[Prototype]]: File}

And the API result is:

dataFile: {}

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

0

You should probably use FormData and multipart/form-data

 const SubmitPDF = () => {
   const formData = new FormData();
   formData.append("dataFile", pdffile);
   axios({
     method: "post",
     url: "url",
     data: formData,
     headers: {
      'Content-Type': 'multipart/form-data'
    }
  }).then(res => {
    console.log("REs", res)
  })
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!