[英]Downloading zip file with AngularJS
When I access this url through browser it will ask me to download the file 当我通过浏览器访问该URL时,它将要求我下载文件
https://some-domain.com/api/v1/file/log123.tar.gz?type=log https://some-domain.com/api/v1/file/log123.tar.gz?type=log
And I need to download this from angularjs http request 我需要从angularjs http请求下载
I written a factory for this, but its not downloading 我为此写了一个工厂,但没有下载
Request getting 200 status but still showing loader in firebug 请求获取200状态,但仍在Firebug中显示加载程序
app.factory('File', ['$http','GENERAL_CONFIG', function($http, GENERAL_CONFIG) {
var API_URL = GENERAL_CONFIG.BASE_API_URL;
API_URL = API_URL + 'filetransfer/';
return {
download: function(filename, type,successcallback, errorcallback){
var apiurl = API_URL + filename + '?type='+type
$http.get(apiurl,{
headers: {
"Content-Type": "application/x-download;"
}
}).success(successcallback).error(errorcallback);
}
}
}]);
This is an old post but I will respond incase of current needs. 这是一个旧帖子,但是如果有当前需求,我会回应。
Your http request should have an additional header. 您的http请求应该有一个附加的标头。 Set responseType: "arraybuffer".
设置responseType:“ arraybuffer”。
Then you can transform that response into a blob obj. 然后,您可以将该响应转换为Blob obj。 and pass it to the callback as such: URL.createObjectURL(new Blob([response]));
然后将其传递给回调:URL.createObjectURL(new Blob([response]));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.