Context: I'm trying to download a binary file from a backend (that requires some data posted as json-body) and save it with file-saver using the filename specified by the backend in the content-disposition header. To access the headers I think I need the HttpResponse.
But I'm unable to use angular's HttpClient.post<T>(...): Observable<HttpResponse<T>>;
method with a Blob.
When I call
this.httpclient.post<Blob>('MyBackendUrl',
params,
{observe: 'response', responseType: 'blob'});
the compiler complains about the 'blob' ('json' is accepted by the compiler):
error TS2345: Argument of type '{ observe: "response"; responseType: "blob"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'observe' are incompatible.
Type '"response"' is not assignable to type '"body"'.
When I put the options in an own object as seen in https://mcmap.net/q/340402/-using-the-request-method-in-angular-39-s-httpclient-class (but without the "as" ...) the post(...):Observable is called and I cannot access the headers.
Btw, even the simple example return this.http.get<Blob>('backendUrl', {responseType: 'blob'});
as seen e.g. in https://mcmap.net/q/340403/-angular-4-3-getting-an-arraybuffer-with-new-httpclient doesn't work for me.
Versions used
- Angular Version: 5.0.3 (will be updated to latest 5 in a week or so)
- typescript: 2.4.2
- webpack: 3.8.1