am试图从结构类似的本地文件夹下载pdf文件 资产/test.pdf。
app.get('/ePoint', (req,res)=>{
// some dumb code :P
});
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。但在正常的浏览器控制台中显示如下附件
注意:我从here引荐ts文件
非常感谢