Attempting to download a zip file from my server using a Spring MVC controller. Here is the AngularJS (1.5) controller code I am using to achieve this:
$http({
url: '/myurl',
method: 'GET',
headers: {
'Content-type': 'application/zip'
},
responseType: 'arraybuffer'
}).success(function (data,status,headers) {
var blob = new Blob([data], {type: "application/zip"});
var objectUrl = URL.createObjectURL(blob);
var file = headers('Content-Disposition');
window.open(objectUrl);
});
The above code works, but I need to specify the file name that I am receiving in the response header. When trying to use the file name obtained from header('Content-Disposition'), it currently gives a random file name.
I attempted the following code which works in Chrome but not in Mozilla. Is there a solution that can work across all browsers?
//var anchor = document.createElement("a");
//anchor.download = "ATMOSLogFiles.zip";
//anchor.href = objectUrl;
//anchor.click();
Appreciate any assistance provided! Thank you.