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

114
Views
getting empty object while sending formData

I'm trying to upload an image and then send it to the server. But turns out I'm sending an empty object to the server. I'm not using any form. Just through input tag. Is the code correct?

html:

 <div>
    <input type="file" class="fileUpload" name="file"/>
 </div>

js:

 document.querySelector('.fileUpload').addEventListener("change", function(e){

       let formData = new FormData();
       formData.append('imageFiles', e.target.files[0])



     // for(var v of formData) {
     //   console.log(v[0]+', '+v[1]);
     // } i tried to check here and it gives `imageFiles, [object File]`. This made me 
      // think there is data so sent it to server.
       

       fetch(`/image`, {
         method: 'POST',
         headers: { 'Content-Type': 'application/json' },
         body: JSON.stringify(formData)
        }).then(res => console.log(res))
        .then(json => console.log(json))
        .catch(err => console.log(err));
  }) 

node.js:

 app.post('/image', (req, resp) => {

  console.log(req.body)// but get empty object on server {}

})
about 4 years ago · Santiago Trujillo
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!