I need to download a zip file by making post request. Fraom backend they are zipping the file and sending.
Backend Values they set
Content-Disposition →attachment;
filename="sample.zip"
Content-Type →application/zip
UI Code:
downloadMethod = function (path, item) {
var promise = $http({
method: "POST",
data: item,
url: API_SERVER.url+path,
headers: { 'Content-Type': 'application/zip; charset=UTF-8'},
responseType: 'arraybuffer'
});
promise.success(function(response, status, headers, conf) {
return response;
}).error(function(response){
return response;
});
return promise;
};
On Success i am saving the file using Filesaver
var blob = new Blob([data)], {type:"application/zip"});
saveAs(blob, "sample.zip");
The file is downloading. But while extracting the file I am getting the error
ERROR: CENTRAL DIRECTORY NOT FOUND
and also m getting File cannot be opened or it is not a valid zip file.
But when i try to hit the api from postman it is download and i can able to extract the file.