A
A
Alexey Yarkov2016-05-10 20:41:22
Node.js
Alexey Yarkov, 2016-05-10 20:41:22

How to make a file download using express?

Can't get the file to download. I make a selection from Mongo, convert to CSV and write the following code:

// data содержит строку в формате CSV
res.header('Content-Disposition', 'attachment; filename=export.csv');
res.header('Content-Type', 'text/csv; charset=utf-8');
res.header('Content-Length', data.length);
res.write(data);
res.end();

I send a request from Angular using the $http({url: "api/export/csv", method: "GET"}) method.
As a result, the data is simply sent to the browser, but the export.csv file needs to be downloaded.
I don’t want to fence a crutch with saving / deleting the file))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-05-10
@Chuv

Have you tried google?
stackoverflow.com/questions/17836273/export-javasc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question