【问题标题】:Download application/PDF with Node.js使用 nodejs 下载应用程序/pdf
【发布时间】:2021-01-07 11:39:08
【问题描述】:

我正在从出站 API 接收带有以下标头的文件

内容如下所示

对于一些如何在我的临时目录中保存这样的文件并且无法保存这样的文件。保存后文件看起来不对。 这有办法以正确的方式保存它。

 axios.get(process.env.SOZLESME_IMZA_API + '/downloadfile?SignerId=' + req.body.SignerId + '&FileKey=' + req.body.FileKey,
await getHeaders())
    .then(response => {
 // save here      
 
  //      helper.sendResult(res, response.data, null, req);
    })
    .catch(err => {
        helper.sendResult(res, null, err, req);
    });

【问题讨论】:

    标签: node.js blob downloadfile


    【解决方案1】:

    你应该'downloadjs'节点模块来下载一个pdf文件。

    const download = require('downloadjs');
    
    ...
    
        const specificationId = this.$route.params.specificationId;
    
        axios
            .get(process.env.SOZLESME_IMZA_API + '/downloadfile?SignerId=' + req.body.SignerId + '&FileKey=' + req.body.FileKey, {
                headers: await getHeaders(),
                responseType: 'blob', // browser only option
            })
            .then(response => {
               const content = response.headers['content-type'];
               download(response.data, file_name, content);
            })
            .catch(error => console.log(error));
    
    ...
    
    

    【讨论】:

    • 这对我不起作用。 downloadjs 是一个客户端脚本,当它用作后端时将无法与 nodejs 一起使用。
    猜你喜欢
    • 2011-05-30
    • 2018-02-15
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2020-04-15
    • 1970-01-01
    相关资源
    最近更新 更多