【发布时间】:2020-09-07 14:15:40
【问题描述】:
我有一个 WebApi 方法,它将一个字节数组返回到一个角度前端。 我已经尝试了一切,从将其读取为 Blob,将其读取为数组缓冲区,将其从字节数组转换为 Blob,但没有任何效果。每次我收到无法打开 pdf 错误。
组件中的示例代码:
this.service.getPDF().subscribe((response)=>{
let file = new Blob([response], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
service.ts 中的示例代码:
getPDF(){
const url = `${this.serviceUrl}/pdf`;
const httpOptions = {
'responseType' : 'arraybuffer' as 'json'
//'responseType' : 'blob' as 'json' //This also worked
};
return this.http.get<any>(url, httpOptions);
}
【问题讨论】:
标签: c# arrays angular pdf webapi