I have encountered an issue with my code while using angularjs http post to download a file from the Web Api. The code works perfectly fine in Google Chrome and Firefox, however it fails in Internet Explorer. Here is the code snippet:
$scope.CallApi = function () {
$http({
url: some url,
dataType: 'json',
method: 'POST',
data: null,
responseType: 'arraybuffer',
}).success(function (responsedata, status, xhr) {
var file = xhr('Content-Disposition');
console.log(file);
var filename = file.substr(21, 7);
$scope.value = responsedata;
var fileName = filename;
var blob = new Blob([responsedata], { type: "application/octet-stream" });
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = fileName;
}).error(function (error) {
alert("Error Found" + " : " + error);
});
};
The above code does not work in Internet Explorer. I prefer not to use FileSaver.js extension. Is there any alternative way to download the file from api in Internet Explorer? Attached below is the screen shot of the error message I am receiving in Internet Explorer: https://i.sstatic.net/CF1Ti.png Thank you in advance.