【发布时间】:2017-04-21 04:28:34
【问题描述】:
我想使用 rest api 从 angular 2 的客户端下载 xlsx 文件。
我从我的 GET 请求中得到一个字节数组作为响应,我将它发送到带有 subscribe 的下载函数:
let options = new RequestOptions({ search: params });
this.http.get(this.restUrl, options)
.subscribe(this.download);
使用blob的下载功能:
download(res: Response) {
let data = new Blob([res.arrayBuffer()], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;' });
FileSaver.saveAs(data, this.fileName);};
我的问题是我的文件一直损坏。 我尝试了很多版本,但没有任何效果。
** 也尝试了这个解决方案,但它不起作用(xlsx 文件仍然损坏) - Angular 2 downloading a file: corrupt result,区别在于我的数据是数组Buffer而不是string或者json,PDF和xlsx是有区别的。
10 倍!
【问题讨论】:
标签: angular typescript blob