How can I set headers of a http client POST request in order to send both a bearer token and a response Type of type blob?
My current code is this:
public saveBook(format: string, req: Book) {
var mediaType = 'application/pdf';
this.http.post(this.ApiUrl + '/PDFBook', req, { responseType: "blob" }).subscribe(
(response) => {
var blob = new Blob([response], { type: mediaType });
saveAs(blob, 'Book.' + format.toLowerCase());
});
}
And I need to append to the current header this bearer:
let headers = new HttpHeaders().set('Authorization', 'Bearer ' + localStorage.getItem('session_token'));
How can I do that?
EDIT:
I've tried doing this:
let headers = new HttpHeaders().set('responseType', 'blob')
.set('Authorization', 'Bearer ' + localStorage.getItem('session_token'));
But I get a parsing error because it isn't able to find 'responseType'