Я хочу иметь возможность загрузить файл (здесь, используя блоб). Для этого мне нужно получить имя файла с сервера, который встроен в заголовок «content-disposition». Вот моя функция:
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);
Но я получил ошибку:
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"'.
Когда я go к определению функции, я получаю:
/**
* 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>>;
Я не понимаю, что я делаю не так. Можете ли вы помочь мне, пожалуйста?
Спасибо за вашу помощь!