我正在从后端获取文件流。标头保留带有扩展名的文件名。但是如何最终获得那些财产。这是我的代码,没有得到值也没有错误。
downloadFile(id:number):Observable<any> {
const options = { responseType: 'blob' as 'json' }
return this.http.get<any>(environment.baseUrl+`CourseFileUpload/${id}`, options)
.pipe(
map((file) => {
console.log('header', file.headers('Content-Disposition')); //not getting header value...!?
return new Blob([file], {type: "application/octet-stream"})
}),
catchError(this.handleError)
)
}
有人帮我吗?
我尝试了以下建议:
downloadFile(id:number):Observable<any> {
const headers = new HttpHeaders({ observe: 'response'});
const options = { responseType: 'blob' as 'json', headers:headers }
return this.http.get<any>(environment.baseUrl+`CourseFileUpload/${id}`, options )
.pipe(
map(resp => {
if(resp.headers){
const keys = resp.headers.keys();
console.log('file', keys); //nothing consoles!?
}
return new Blob([resp], {type: "application/octet-stream"})
}),
catchError(this.handleError)
)
}
没有回应。请任何人帮助我获取响应标头?