Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda