【发布时间】:2015-09-15 08:03:42
【问题描述】:
在我的 Node/Express 应用程序中,我有以下代码,假设从文件中读取 PDF 文档,并将其发送到浏览器:
var file = fs.createReadStream('./public/modules/datacollectors/output.pdf', 'binary');
var stat = fs.statSync('./public/modules/datacollectors/output.pdf');
res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=quote.pdf');
res.pipe(file, 'binary');
res.end();
我没有收到任何错误,但我也没有在浏览器中获取文件。 我做错了什么?
【问题讨论】:
-
一个重要细节 - 我正在尝试将文件发送回浏览器以响应 http POST