I'm trying to set up a file download feature using a blob, but I need to extract the filename from the server's "content-disposition" header. Here's the code I have:
const header = {Authorization: 'Bearer ' + token};
const config = {headers: header, responseType: 'blob' as 'blob', observe: 'response' as 'response'};
return this.http.get<HttpResponse<Blob>>(url, config);
However, I encountered this error:
error TS2345: Argument of type '{ headers: { Authorization: string; }; responseType: "blob"; observe: "response"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
Types of property 'observe' are incompatible.
Type '"response"' is not assignable to type '"body"'.
Looking at the function definition, it appears to be constructed for handling `GET` requests that expect a Blob response:
/**
* Constructs a `GET` request that interprets the body as a `Blob` and
* returns the full `HTTPResponse`.
*
* @param url The endpoint URL.
* @param options The HTTP options to send with the request.
*
* @return An `Observable` of the `HTTPResponse` for the request,
* with the response body as a `Blob`.
*/
get(url: string, options: {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
observe: 'response';
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
If you can help me understand what I might be doing wrong, I would greatly appreciate it.
Thank you for your assistance!