I am working on an Angular 6 project. One of the web service return the octet-stream of a file. I have to create a Blob of the file and download it. I am not getting the response inside subscribe. How can I request for non-json octet-stream response?
downloadFile(filePath: string): Observable<HttpResponse<Any>> {
this.http.post<any>(this.getFileDownloadPath(), { stringParam: filePath }, { observe: 'response' }).subscribe(
(resp) => {
this.triggerDownloadFile(resp.body);
},
(err) => {
console.log('err');
}
);
}
triggerDownloadFile(data: Response) {
const blob = new Blob([data], { type: 'application/octet-stream' });
const url = window.URL.createObjectURL(blob);
window.URL.revokeObjectURL(url);
window.open(url);
}
responseType: 'blob'to your post options