Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda