【发布时间】:2021-02-18 19:59:12
【问题描述】:
我正在尝试使用已存在于模拟测试数据下的 pdf 下载 pdf 而没有提示。而且我可以使用下面的代码完成上述任务。但是当我尝试打开下载的 pdf 时,我得到“无法加载 pdf 文档”我在这里缺少什么。请帮助。
fs.readFile('./src/test-data/service/print/notes.pdf', function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Disposition': 'attachment; filename=notes.pdf'
});
res.end(content, 'utf-8');
}
});
【问题讨论】: