Ниже приведен вызов от компонента, который загружает большой двоичный объект, совместимый с IE и chrome:
this.subscribe(this.reportService.downloadReport(this.reportRequest, this.password), response => {
let blob = new Blob([response], { type: 'application/zip' });
let fileUrl = window.URL.createObjectURL(blob);
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileUrl.split(':')[1] + '.zip');
} else {
this.reportDownloadName = fileUrl;
window.open(fileUrl);
}
this.spinner = false;
this.changeDetectorRef.markForCheck();
},
error => {
this.spinner = false;
});
Ниже приведен метод обслуживания, который определяет тип ответа «blob»
downloadReport(reportRequest: ReportRequest, password: string): Observable<any> {
let servicePath = `${basePath}/request/password/${password}`;
this.httpOptions.responseType = 'blob';
return this.endpointService.post(endpoint, servicePath, reportRequest, this.httpOptions);
}
Ниже приведен код вызова httpClient:
//Make the service call:
let obs = this.httpClient.request(method, url, options);
//Return the observable:
return obs;