当我尝试下载大于50kb的任何内容时发生错误。我尝试了很多方法:在zone.runOutsideAngular中使用标准的角度http客户端,xhr请求,xhr请求。但接缝每次都会犯同样的错误。但是,当我测试来自vanilla javascript的相同请求时,它就像一个魅力。我的请求的文字看起来像这样。
this.zone.runOutsideAngular(() => {
let url = environment.backEndHttpsUrl + 'some_backend_path';
this.xhr.withCredentials = true;
this.xhr.responseType = 'blob';
this.xhr.open('GET', url, true);
const fileName = 'some name constructing method';
this.xhr.onload = () => {
console.log(this.xhr.response);
let blob = this.xhr.response;
FileSaver.saveAs(blob, fileName);
};
this.xhr.send();
});
使用角度httpClient的方法:
return this.http.get(environment.backEndHttpsUrl + 'some request building logic',
{
withCredentials: true,
responseType: 'blob',
}).toPromise()