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

104
Visualizações
How to parse a fetch response with object and file

My fetch response has two parts, an object and an excel file. If I make the server send only the excel file, then response.blob() does the job, but I cant make it work when there's both an object and a file in the response.

Doing response.json() works enter image description here

but then the excel file turns into a buffer string which gets corrupted when I try to download the file

    const json = await response.json()

    const formatted_excel_file_or_error = await json.formatted_excel_file_or_error

    // turns buffer string into buffer

    const buff = await buffer.Buffer.from(formatted_excel_file_or_error,'utf-8')

    console.log(buff)

    // turns buffer into blob

    const blob = await new Blob([new Uint8Array(buff)], {type: 'application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})

    console.log(blob)
    await download(blob, 'test.xlsx', 'application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

enter image description here

My question is, is there a proper way to handle a response that has a file AND object, and if not what am I doing wrong with the conversion from buffer to blob download

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