问题对人有帮助,内容完整,我也想知道答案0问题没有实际价值,缺少关键内容,没有改进余地
使用express框架下载文件,但是失败了,直接看代码
express 主页 I love you!以下是node.js代码 var express = require("express"); var app = express(); app.use(express.static('public')); app.locals.title = "My app"; app.get("/",function(req,res){ console.log("resquest has been received!"); res.sendFile("public/index.html"); res.end(); }) app.get("/download",function(req,res){ res.download('public/example.jpg','example.jpg',function(err){ if(err) console.log(err); else console.log("download successfully"); }); }) app.listen(3000); console.log("OK");

求解疑
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的下载按钮我建议直接写成
注意res.download方法的第一个参数
res.download('/report-12345.pdf', 'report.pdf', function(err){ if (err) { // Handle error, but keep in mind the response may be partially-sent // so check res.headersSent } else { // decrement a download credit, etc. } });然后你的图片虽然尺寸很大,但是太模糊了。。。