小编Luk*_*uke的帖子

Angular 4.3:使用新的HttpClient获取数组缓冲区

我想换成新的HttpClient.到目前为止我处理文件下载如下:

getXlsx (): Observable<any> {
    return this.http.get('api/xlsx', {
      responseType: ResponseContentType.ArrayBuffer, // set as ArrayBuffer instead of Json
    })
    .map(res => downloadFile(res, 'application/xlsx', 'export.xlsx'))
    .catch(err => handleError(err));
  }

export function downloadFile(data: any, type: string, filename: string): string {
  const blob = new Blob([data._body], { type });
  const url = window.URL.createObjectURL(blob);

  // create hidden dom element (so it works in all browsers)
  const a = document.createElement('a');
  a.setAttribute('style', 'display:none;');
  document.body.appendChild(a);

  // create file, attach to hidden element and open hidden element
  a.href = …
Run Code Online (Sandbox Code Playgroud)

blob httpclient arraybuffer angular

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

标签 统计

angular ×1

arraybuffer ×1

blob ×1

httpclient ×1