Angular HttpClient : Property 'headers' does not exist on type 'Blob'

标签 angular blob httpclient

<分区>

我正在使用 angular 5,这是我从服务器下载文件的代码:

1- 服务:

export(url) {
return this.http.get(url, {responseType: 'blob'});

2-组件代码:

  public downloadfile(file: any) {

    var resp: any;
    this.documentsService.export('http://localhost:55650/api/files/attachment/' + file.docf_GUID)
        .subscribe(
            (data) =>{  
                resp = data, saveAs(resp), console.log(resp.headers) },
            () => { }
        );
}

但是当我尝试获取响应 header 时出现此错误:

error TS2339: Property 'headers' does not exist on type 'Blob'.

最佳答案

默认返回响应正文。您必须通过将 observe 参数添加到 httpOptions 来明确设置方法以返回 reposne。

return this.http.get(url, {responseType: 'blob', observe: 'response'});

关于 Angular HttpClient : Property 'headers' does not exist on type 'Blob' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49504953/

相关文章:

javascript - 如何将低精度数字(2-10 位)写入数组缓冲区/blob?

java - 如何在 Google App Engine 中处理 Blob,而不是 Cloud Storage 和 BlobStore API

angular - 如何在 HttpClient "get"方法中传递 URLSearchParams - Angular 5

Android HTTP GET 不起作用

angular - 在带有模板的 Angular ng-bootstrap 模式中,关闭和关闭按钮不起作用

Angular 7 - 获取 HTML 中声明的所有组件的组件实例

angular - [attr.disabled] ="true"在 anchor 标记中不起作用

javascript - FormArray 无效但不包含错误

mysql - 将大文件上传到 BLOB

java - HttpClient 上严格可靠的超时