How to download a zip file in AngularJS
To download a binary file type such as a zip file, it is important to set the responseType
before doing the XHR.
var config = { responseType: "blob" };
var promise = $http.get(url, config);
promise
.then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
...
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
...
});
For more information, see MDN Web API Reference - XHR responseType.