在我的Ext Js解决方案中,我正在调用一个返回
JSON格式的服务
{"success":true,"filename":"spreadsheet.xlsx","file":[80,75,3,4,20,...(many more)]}
UPDATE
所以我发现这一点开始downlaod
var a = window.document.createElement('a'); a.href = window.URL.createObjectURL(new Blob(data.file,{ type: 'application/octet-stream' })); a.download = data.filename; // Append anchor to body. document.body.appendChild(a) a.click(); // Remove anchor from body document.body.removeChild(a)
到目前为止好
解决方法
我将文件转换成Uint8Array,然后将其传递给Blob
var arr = data.file; var byteArray = new Uint8Array(arr); var a = window.document.createElement('a'); a.href = window.URL.createObjectURL(new Blob([byteArray],{ type: 'application/octet-stream' })); a.download = data.filename; // Append anchor to body. document.body.appendChild(a) a.click(); // Remove anchor from body document.body.removeChild(a)
阅读这个答案帮助了很多https://stackoverflow.com/a/16245768/1016439