获取下载到angularjs和前press.js之间工作 [英] Getting downloads to work between angularjs and express.js
本文介绍了获取下载到angularjs和前press.js之间工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以得到我请求文件的原始数据,但我不能让浏览器的文件服务给用户。我是否需要使用iframe的?
//客户端code
download_file:功能(路径,回调){
$ http.post('/下载/ client_file',{路径:路径})。
成功(功能(数据,状态,头,配置){
的console.log(数据); //这包含res.download的原始数据
//从服务器。
});
} //服务器code
res.download(文件); //路径是正确的
解决方案
我用下面的code在我services文件下载的项目和它的工作太棒了。我是从的http://filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/
$('<形式的行动=+ URL +'的方法='+('后')+'>'+投入+'< /表&GT ;')
。.appendTo(身体)提交()删除();
I can get the raw data of the file that I am requesting, but I can't get the browser to serve the file to the user. Do I need to use iframes?
//Client code
download_file: function (path, callback) {
$http.post('/download/client_file', {path:path}).
success(function(data, status, headers, config) {
console.log(data); //this contains the raw data of the res.download
//from the server.
});
}
//server code
res.download(file); // the path is proper
解决方案
I used the code below in my services file for downloading items and it worked great. I got it from http://filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/
$('<form action="'+ url +'" method="'+ ('post') +'">'+inputs+'</form>')
.appendTo('body').submit().remove();
这篇关于获取下载到angularjs和前press.js之间工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文