Angular 5-Node / Express-无法下载pdf

时间:2018-10-24 11:37:40

标签: node.js angular express

am试图从结构类似的本地文件夹下载pdf文件 资产/test.pdf。

server.js

app.get('/ePoint', (req,res)=>{
 // some dumb code :P
});

demo.ts

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Headers } from '@angular/http';
import {Observable} from 'rxjs'; 
fileDownload() {
    const headers = new HttpHeaders();
    headers.append('Accept', 'application/pdf');
    this._http.get('http://localhost:3000/ePoint',  { headers: headers })
      .toPromise()
      .then(response => this.saveItToClient(response));
  }
    private saveItToClient(response: any) {
    const contentDispositionHeader: string = response.headers.get('Content-Disposition');
    const parts: string[] = contentDispositionHeader.split(';');
    const filename = parts[1].split('=')[1];
    const blob = new Blob([response._body], { type: 'application/pdf' });
    saveAs(blob, filename);
  }

我不知道我在哪里弄错了。在浏览器网络控制台中。显示200 ok。但在正常的浏览器控制台中显示如下附件

enter image description here enter image description here

注意:我从here引荐ts文件

非常感谢

0 个答案:

没有答案