My issue is similar to this one but it was an old post without much context or detail, so here's what I got:
When my component calls the download file method, which in turn calls the download file service, the service makes the HTTP GET request from my API which streams a blob back to service.
Component:
this.svc.getDownloadFile(fileID, fileName).subscribe(res => {
console.log(res);
});
}
Service:
getDownloadFile(fileId: number, fileName: string): Observable<any> {
return this.http.get(this.downloadFileUrl + "/" + fileId, {
reportProgress: true,
observe: "events",
headers: this.getHeaders(),
responseType: "blob"
});
}
The problem is that because it is an API call, the blob streams through the XHR and I can see it downloading and its progress in the Network tab in Chrome. The problem I am having is getting some sort of browser download notification that you would usually expect when downloading a file in Chrome (or any browser), this only happens after the entire response is complete.
For example I have a 50MB file in the database. The user clicks a link to download the said file from Angular app, the component calls the service which in turn does an API call which gets the file from the DB and streams it as a blob response. Angular takes this response, waits until it has downloaded all 50MB then shows the download dialog.
The API is returning the Content Disposition header along with content length, content type , filename etc. I have googled all over and searched high and low for something to mimic this, I kind of understand that the browser doesn't automatically download it as usual because the request is being piped through Angular and the browser doesn't automatically just assume that all blob XHR should be saved.
I tried using: https://www.npmjs.com/package/streamsaver but this package actually only handles files that are already stored, not ones being sent from API as blobs.