我知道已经有一个答案了:
Download a file from NodeJS Server using Express
但是浏览器下载对话框中显示的文件名仍然存在问题。
我编写的代码:
private static async GetReport(req : Request, res : Response, route : myRoute)
{
let data = route.mReportMap[req.query.guid];
res.attachment(path.join(data.ReportPath, data.ReportFileName));
console.log('*** HEADER CONTENT ***');
console.log('x-powered-by: ' + res.getHeader('x-powered-by'));
console.log('access-control-allow-origin: ' + res.getHeader('access-control-allow-origin'));
console.log('content-type: ' + res.getHeader('content-type'));
console.log('content-disposition: ' + res.getHeader('content-disposition'));
res.download(path.join(data.ReportPath, data.ReportFileName), data.ReportFileName);
}
控制台说:
*** HEADER CONTENT ***
x-powered-by: Express
access-control-allow-origin: *
content-type: application/zip
content-disposition: attachment;
filename="20180724_Report.zip"
2018-07-24 12:05:23|debug| POST /api/test/report/download?guid=b27fee1f-7da5-437c-9103-5da58ab01df8 HTTP/1.1 from http://localhost:4200/ with response 200 557458
浏览器下载对话框显示的内容:
我做错了什么?
谢谢。
答案 0 :(得分:0)
问题已过时。
我们团队中的某人在前端编码了一个静态文件名(出于测试目的)... 现在,我磨了双手斧头,只是为了测试目的...;-D
仍然感谢您的时间。