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

150
Vistas
Form data Error Cannot set headers after they are sent to the client

Trying to upload a image to azure storage blob But the fetch method doesn't works

It works properly in postman but shows error in fetch

Not problem in heroku deployment

What is the problem in this code

This is the code i have tried :

const uploadImage = async () => {
    try {
      const Data = new FormData();

      Data.append('file', image);

      console.log("form data", Data);

      await fetch('https://fame-azure.herokuapp.com/aa', {
        method: 'POST',
        body: Data
      })
    } catch (err) {
      console.log(err);
    }

code in backend :

app.post('/aa', upload.any(), function (req, res, next) {
  console.log(req.files)
  res.send('ok')
  res.status(200).send('Uploaded: ' + req.files)
})

Error :

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is because in your backend, you are first sending a response with res.send('ok'). After that you are again sending a response with res.status(200).send('Uploaded: ' + req.files), however as the response was already submitted, you cannot update/send it again thus the error. If you simply remove the first line, the error would be gone.

about 4 years ago · Juan Pablo Isaza Denunciar

0

This is because you are trying to send response twice.

app.post('/aa', upload.any(), function (req, res, next) {
  console.log(req.files)
  // res.send('ok') <-- remove this
  res.status(200).send('Uploaded: ' + req.files) // <-- use this
  res.json({uploaded: req.files}) // <-- or this, using json() method will set the response headers 200 automatically
})

If u think it looks fine in postman, is because the postman doesnt receive any error response from your server, the error only logged in your server.

about 4 years ago · Juan Pablo Isaza Denunciar
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