Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!