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

303
Visualizações
response a file from buffer, the request is made twice to be downloaded

I have an express nodejs server which does some calculations and creates a pdf file and sends it as the response. the problem is, when the user tries to download the file, the endpoint is called twice by the browser so the calculations are done twice and it will take twice as long and it will take around 20 seconds for the request to be answered . i checked and saw that the endpoint itself is called twice not favicon.ico or other things.

the file is not saved on the server and is created as buffer and then piped to the client. and the endpoint is not called by the frontend code or fetched by something, it is just opened in a new tab in the browser. some of the codes are listed below:

let buffer =  await createPdfBuffer() // a custom function that creates the pdf as buffer
const readStream = new stream.PassThrough();
    readStream.end(buffer);
    res.set('Content-disposition', 'attachment; filename=' + file.pdf);
    res.set('Content-Type', 'application/pdf');
    readStream.pipe(res);

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