如何使用 node.js 允许客户端下载存储在服务器中的 pdf 文件。
请有人帮我解决这段代码。
fs.readFile('temp/xml/user/username.pdf',function(error,data){
if(error){
res.json({'status':'error',msg:err});
}else{
res.json({'status':'ok',msg:err,data:data});
}
});
最佳答案
Express 有 2 种方便的方法可用于发送文件。区别在于:
-
res.sendfile('temp/xml/user/username.pdf');
或 with
Content-Disposition
建议保存到磁盘:res.download('temp/sml/user/username.pdf');
关于node.js - 如何在node.js服务器的客户端下载存储在服务器中的pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18393166/