【问题标题】:Download filename from NodeJS Server using Express使用 Express 从 NodeJS 服务器下载文件名
【发布时间】:2018-07-24 10:29:31
【问题描述】:

我知道已经回答了一个问题:
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

浏览器下载对话框显示的内容:

我做错了什么?

提前致谢。

【问题讨论】:

    标签: node.js rest express download filenames


    【解决方案1】:

    问题已过时。

    我团队中的某个人在前端编写了一个静态文件名(用于测试目的)... 现在我磨我的双手斧头,只是为了测试目的......;-D

    感谢您的宝贵时间。

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 2019-03-30
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 2015-06-14
      相关资源
      最近更新 更多