Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文件下载字节数组作为javascript/Extjs中的文件_Javascript_Extjs3 - Fatal编程技术网

文件下载字节数组作为javascript/Extjs中的文件

文件下载字节数组作为javascript/Extjs中的文件,javascript,extjs3,Javascript,Extjs3,在我的ExtJS解决方案中,我调用了一个返回此JSON格式的服务 {"success":true,"filename":"spreadsheet.xlsx","file":[80,75,3,4,20,0,...(many more)]} 如何使用文件名和字节数组(文件)的内容创建文件下载对话框 更新 所以我找到了这一点来启动downlaod var a = window.document.createElement('a'); a.href = wind

在我的ExtJS解决方案中,我调用了一个返回此JSON格式的服务

{"success":true,"filename":"spreadsheet.xlsx","file":[80,75,3,4,20,0,...(many more)]}
如何使用文件名和字节数组(文件)的内容创建文件下载对话框

更新

所以我找到了这一点来启动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)
到目前为止还不错


但是我得到的文件已损坏,因此我怀疑需要对文件变量进行编码/解码?

在将文件传递到Blob之前,我必须将其转换为Uint8Array

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)

阅读此答案有很大帮助

基于Jepzen的回答,我能够使用此技术从浏览器中从AWS S3下载文档+1杰普森

s3.getObject(参数、函数(错误、数据){
if(err==null){
var arr=data.Body;
var byteArray=新的UINT8阵列(arr);
var a=window.document.createElement('a');
a、 href=window.URL.createObjectURL(新Blob([byteArray],{type:'application/octet stream'}));
a、 download=fName;//fName是作为params中键值的一部分传入的键的文件名部分。
//在主体上附加锚。
document.body.appendChild(a)
a、 单击();
//从车身上拆下锚固件
document.body.removeChild(a)
}否则{
结果='失败'
log(“检索对象失败:+err”);
}
});

看一看:我花了很多时间在这个问题上,但编码错误。谢谢你的解决方案。我使用的是UINT16Arrayal,请看这里: