小编Raj*_*Raj的帖子

将字节数组转换为 blob(pdf 文件)并使用 angular 5 下载

我从服务器端收到一个字节数组,并已成功将其转换为 blob。但是,当我尝试下载它时,它显示文件已损坏。以下是我的代码 -

// In client side controller
this.contractsService.downloadPdf(id)
      .then((result) => {
        var blob = new Blob([result], { type: "application/pdf" });
        var link = document.createElement('a');
        link.href = window.URL.createObjectURL(blob);
        link.download = "testing.pdf";
        link.click();
      });
Run Code Online (Sandbox Code Playgroud)

和,

// In client side service
private headers = new HttpHeaders({ 'Content-Type': 'application/json' });
downloadPdf(id: number) {
    return this.http.get(this.apiRoutes.download + "/" + id, { headers: this.headers })
      .map((res: any) => res)
      .toPromise();
  }
Run Code Online (Sandbox Code Playgroud)

任何形式的帮助将不胜感激。谢谢你。

asp.net-core angular5

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular5 ×1

asp.net-core ×1