I facing an error while building a jhipster project that says that I need to change the parameter responseType
in a get
request.
Here's the error:
Argument of type '{ responseType: "arraybuffer"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'responseType' are incompatible. Type '"arraybuffer"' is not assignable to type '"json"'. Version: typescript 2.7.2
As you see typescript
is telling me to change the value from arraybuffer
to json
, but I need to keep it as arraybuffer
since I am dealing with a file and I fully aware that the responseType
can be set to arraybuffer
, blob
, json
or text
.
Here's the code
showfile(file?: any): Observable<any> {
return this.http.get<any>(SERVER_API_URL + `leave/api/downloadFile/${file}`, { responseType: 'arraybuffer' });
}
this.http.get<any>
删除任何
When I need to call an endpoint that is returning a file, I usually use the type Observable<HttpResponse<Blob>>
.
Try:
showfile(file?: any): Observable<HttpResponse<Blob>> {
return this.http.get(SERVER_API_URL + `leave/api/downloadFile/${file}`, { responseType: 'blob' });
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.