nodejs流到pdf问题

时间:2018-12-07 14:25:49

标签: node.js angular blob

我在Express中使用nodejs来服务Angular应用程序。首先,使用nodejs ftp从FTP提取文件。该流是通过api发送的,并且还可以,这说明该流无法再次将文件转换为pdf。

Nodejs-Express辅助代码;

var c = new Client();
    c.on('ready', function () {
        c.get('USTYAZILAR\\USTYAZI-1000453-1-A1-1.PDF', function (err, stream) {
            if (err) throw err;
            stream.once('close', function () {
                c.end();
            });
          var aa = stream.pipe(fs.createWriteStream('d:\\tempfiles\\USTYAZI-1000453-1-A1-1.PDF'));
          res.status(200).send(aa);
        });
    });.......

角度角代码;

this.http.post(cons.baseUrl + '/common/get_file', { path: 'x/y/z' }, { responseType: 'arraybuffer' }).toPromise()
      .then((response: any) => {
         const file = new Blob([response], {type: 'application/pdf'});
         const fileURL = URL.createObjectURL(file);
        window.open(fileURL);
      }).catch(error => {
        console.log(error);
      });

,并且正在接收错误页面,如下图所示; enter image description here

感谢您的帮助;

0 个答案:

没有答案