我尝试从api下载图像(png)。我的问题是,由于某种原因,只有json文件被ionic / angular接受。
return this.http.get(this.authKeys.serverURL, {headers: this.header, responseType: ResponseContentType.Blob});
发生以下错误:
Argument of type '{ headers: any; responseType: ResponseContentType.Blob; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'responseType' are incompatible. Type 'ResponseContentType.Blob' is not assignable to type '"json"'.
出于某种原因,只允许json类型的响应......
responseType
持有字符串值。所以你应该传递这些值中的任何一个
'arraybuffer' | 'blob' | 'json' | 'text';
在早期版本的Angular 2中,它的API被设计为期望responseType
,check here的枚举值