Currently, I am working on a project that involves making API calls to retrieve blob data.
The backend also sends the file name in the header, which is causing some issues for me as I am unable to access the header from the API response.
Below is my code snippet from service.ts:
public openFile(path) {
let url = '/download/';
let pathFile = new HttpParams().set('pathFile', path);
return this.httpClient.get(url, { params: pathFile, responseType: 'blob' });
Within the component.ts, I am calling the service. However, when attempting to print res.headers
, I am only seeing 'undefined' in the console:
openFile(path){
this.creditPoliciesService.openFile(path).toPromise().then (data => {
console.log("dataaaaaa",data.headers); // undefined
var blob = new Blob([data], {type: 'application/pdf'});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
}
else {
var fileURL = URL.createObjectURL(blob);
window.open(fileURL);
}
});
}
Although the developer tools show information in the response headers, I am struggling to access them within the response variable.