之前有人说,“复制”,我只是想确保,即人们知道,我已经审查了这些问题:客户端下载
1)使用的角度和PHP,不肯定这里发生了什么(我不知道PHP):Download zip file and trigger "save file" dialog from angular method
2)不能得到这个答案,做任何事情:how to download a zip file using angular
3)此人已经可以下载,这是过去的时候,我正试图弄清楚: Download external zip file from angular triggered on a button action
4)没有回答这一个: download .zip file from server in nodejs
5)我不知道用什么语言这甚至是: https://stackoverflow.com/questions/35596764/zip-file-download-using-angularjs-directive
鉴于这些问题,如果这仍然是一个重复的,我道歉。这是另一个版本的问题。
我的角度1.5.X客户端给我一个标题列表,其中每个标题都有一个关联的文件。我的节点4.X/Express 4.X服务器获取该列表,获取文件位置,使用npm中的express-zip创建一个zip文件,然后将该文件传回给响应。然后我希望我的客户端启动浏览器的“下载文件”选项。
这里是我的客户端代码(角1.5.X):
function bulkdownload(titles){
titles = titles || [];
if (titles.length > 0) {
$http.get('/query/bulkdownload',{
params:{titles:titles},
responseType:'arraybuffer'
})
.then(successCb,errorCb)
.catch(exceptionCb);
}
function successCb(response){
// This is the part I believe I cannot get to work, my code snippet is below
};
function errorCb(error){
alert('Error: ' + JSON.stringify(error));
};
function exceptionCb(ex){
alert('Exception: ' + JSON.stringify(ex));
};
};
节点(4.X)与快递拉链,https://www.npmjs.com/package/express-zip代码:
router.get('/bulkdownload',function(req,resp){
var titles = req.query.titles || [];
if (titles.length > 0){
utils.getFileLocations(titles).
then(function(files){
let filename = 'zipfile.zip';
// .zip sets Content-Type and Content-disposition
resp.zip(files,filename,console.log);
},
_errorCb)
}
});
这里是我的successCb在我客户端代码(Angular 1.5.X):
function successCb(response){
var URL = $window.URL || $window.webkitURL || $window.mozURL || $window.msURL;
if (URL) {
var blob = new Blob([response.data],{type:'application/zip'});
var url = URL.createObjectURL(blob);
$window.open(url);
}
};
“blob”部分s eems工作正常。在IE的调试器中检查它,它看起来像一个八位字节信息的文件流。现在,我相信我需要将该blob放入一些HTML5指令中,从浏览器启动“另存文件”。也许?也许不会?
由于90%以上的用户使用IE11,我测试了PhantomJS(Karma)和IE中的所有角度。当我运行的代码,我得到的是旧“访问被拒绝”的一个警告窗口错误:
Exception: {"description":"Access is denied...<stack trace>}
建议,澄清,解答等,欢迎!
所以会发生什么?它在哪一点失败?你偶然有一个弹出式窗口拦截器吗? – idbehold
是否有错误?如果手动输入url http:// localhost/query/bulkdownload?titles = 123',你可以下载文件吗? –
哦拍!对不起,让我更新一下。 – westandy