I'm trying to download the .csv file coming from the backend with specific filename. How can i access the filename from the api Response Header using Angular 7

my service (api call):
public getDownloadFile(masterDistributorId: number, runDate: string) {
return this.http.get
(`${environment.apiUrl}command-center/report/download/?
masterDistributorId=${masterDistributorId}&runDate=${runDate}`, {
headers: new HttpHeaders().append('Content-Type', 'application/csv'),
responseType: 'blob',
observe: 'response'
}
);
}
my subscribe call:
public Download(row: DistributorItem) {
console.log(row.masterDistributorId);
console.log(this.RunDate);
this.CommandService.getDownloadFile(row.masterDistributorId, this.RunDate).subscribe(res => {
console.log(res.headers);
this.SaveFile(res);
});
}
HttpResponse<Config>.subscribe(resp => { // display its headers const keys = resp.headers.keys(); this.headers = keys.map(key =>${key}: ${resp.headers.get(key)}); // access the body directly, which is typed asConfig. this.config = { ... resp.body }; }); } Visit angular.io/guide/http for more details. - Raj Kumar