0

I am using xlsx-populate module with node.js. I am sending the workbook as a buffer, as mentioned on their site. I am using postman to hit the API and get the xlsx file as attachment. But the response I am getting has weird characters as shown below:

�2�N��N��+xl/drawings/drawing1.xml����0��>ٻ=C���@`ChB�M�
��M���8�̗�����ً��5��2��i
const workbook = await XlsxPopulate.fromFileAsync(filename);

// await workbook.toFileAsync(outfile);
const data = await workbook.outputAsync();

res.attachment("output.xlsx");
res.send(data);

When I use await workbook.toFileAsync(outfile); to save the file locally, everything works and I can read the file. But when I try to send the file to download using the commands res.attachment("output.xlsx"); and res.send(data);, I get weird characters in the response to Postman.

The response headers have 11 properties which includes:

content-disposition -> attachment; filename="output.xlsx"
content-type -> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Similar steps to download xlsx file using express is also mentioned on the GitHub page of xlsx-populate : https://github.com/dtjohnson/xlsx-populate#serving-from-express

1 Answers1

0

Try using the "Send and download" button in Postman, just click the up arrow on the Send button and you should see this option.

Send and download

Then when you send the request you should be prompted to download the "output.xlsx" file.

I don't think you need to make any coding changes.

Terry Lennox
  • 29,471
  • 5
  • 28
  • 40
  • It worked. But as far as I remember Postman used to prompt the user to save the file. Also would I need to make any other changes to ensure that file is automatically downloaded on front-end browser. – Parth Jaggi Jul 18 '19 at 10:04
  • Maybe the behaviour in Postman changed? I seem to remember that too. I also tested this on Firefox and Chrome and the download works well, so I don't think ant changes should be necessary. – Terry Lennox Jul 18 '19 at 10:12