在Angular中下载文件失败,但得到200响应代码

时间:2019-05-28 12:28:05

标签: angular

我在Angular中下载文件时遇到错误。我收到200成功响应,但无法下载文件。

这是我的代码

//服务文件

  downloadBenefitFile(fileName: string) {
    const token = this._storeService.setStoreData().id_token;
    const headers = new HttpHeaders()
      .set('Authorization', `Bearer ${token}`)
      .set('Content-Type', 'application/octet-stream')
      .set('responseType', 'blob');
    const options = { headers: headers };
    return this._http.get<any[]>(this.documentsUrl + '/Download/' + fileName, options);
  }

//组件文件

    onDocumentDownload(docName: string) {
    console.log(this._documentsService.downloadBenefitFile(docName));
    this._loader.start();
    this._documentsService.downloadBenefitFile(docName).subscribe((resp) => {
      console.log(resp);
      this._loader.stop();
      this._errorService.openErrorPopup('Not implemented yet.');
    }, (error) => {
      this._loader.stop();
      this._errorService.openErrorPopup('Document downloading failed.');
      console.log(error+ "this is where the code hits");          
    });
  }

我收到的回复看起来像这样

%PDF-1.3
1 0 obj
[/PDF /Text /ImageB /ImageC /ImageI]
endobj
7 0 obj
<< /Length 4673 /Filter /FlateDecode >> stream
X   µ\[sÛ8²~ߪùxd*˯[[gKcË3®M

我不确定可能是什么问题

0 个答案:

没有答案