Try this.
res.writeHead(200, {
'Content-Type': 'text/csv'
, 'Content-Disposition': 'attachment; filename=download.csv'
});
문제
On my Node.js server, I have a route that requests data from the database, and converts it from JSON to CSV.
I then state the content type is application/csv, and serve the file.
var csvBlob = json2csv(jsonBlob);
res.writeHead(200, {'Content-Type': 'text/csv' });
res.end(csvBlob);
When I get the file on my client side, it just comes out as 'filename', with no file extension. How do I serve the file with the extension?
My client doesn't necessarily send accept headers asking for CSV, as the request can be called as a simple browser URL, such as:
http://myserver.org/resources/mydbquery/xls
http://myserver.org/resources/mydbquery/csv
http://myserver.org/resources/mydbquery/pdf
해결책
Try this.
res.writeHead(200, {
'Content-Type': 'text/csv'
, 'Content-Disposition': 'attachment; filename=download.csv'
});