This is something that should be easy to fix but right know my mind can't find a solution.
I've got a post like this:
getAccordo(filtro: Filter): Observable<Response> {
return this.http.post<Response>(`${this.ENDPOINT}/export`,
filtro,
{observe: 'response', responseType: 'blob' as 'json'}
)
.catch(error => this.handleError(error));
}
And this is where I use it:
public getAccordo(event: any): any {debugger;
event.preventDefault();
this.accordiService.getAccordo(this.filter).subscribe(
res => {debugger;
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const anchor = document.createElement('a');
anchor.href = window.URL.createObjectURL(blob);
anchor.download = Utils.extractHeaders(res);
anchor.click();
},
error => {
console.log(error);
}
);
}
When I look the chrome console I can see that in the headers there is a content-disposition: attachment; filename="esportazione_accordi_20180905.xlsx"
But in my 'res' this is missing.
What id like to do is to get the filename and use it in anchor.download.
Thank you for the help if you need something more just ask.
EDIT
This is the headers that i get from the Response Headers, I dont see even 1 of them:
On the server side ive added: .header("Access-Control-Expose-Headers", "content-disposition")
But still it doesnt work
EDIT 2:
Ok we are getting closer, I need to get the "filename" value at the end of the pic and assign that to anchor.download.