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

209
Views
Download XLSX via Axios from Express.js server does not work

Server:

return res.download(filepath);

Client:

function provideDownload(filename, data) {
  const linkElement = document.createElement('a');
  linkElement.setAttribute('href', data);
  linkElement.setAttribute('download', filename);
  document.body.appendChild(linkElement);
  linkElement.click();
  linkElement.remove();
}

function provideBlobDownload(filename, data) {
  provideDownload(
    filename,
    window.URL.createObjectURL(new Blob([data]))
  );
}

axios.post('/export', {
  entity, fileformat, locale: props.locale,
}).then((res) => {
  provideBlobDownload(filename, res.data);
});

Problem:

Can't open downloaded xlsx file. Message: File might be corrupted.

API response in browser console looks like:

UEsDBAoAAAAAAPC1eVTWknwRWgEAAFoBAAARAAAAZG9jU....

I have already read through related posts including this one How to save .xlsx data to file as a blob but I couldn't solve it.

I'd like to solve it without using an additional package like exceljs

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try adding responseType:'blob' to request config option:

axios.post('/export', {
    entity,
    fileformat,
    locale: props.locale
}, {
    responseType: 'blob'
})
.then((res) => {
    provideBlobDownload(filename, res.data);
});
about 4 years ago · Juan Pablo Isaza Report
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!