Reputation: 343
Using Easyzip I am trying to zip a folder along with its files. The below mentioned code is not working properly. I get an error 'error occurred while extracting files'. Is there any other method to zip a folder with all its files and subfolders?
Here is my back-end code :-
var zip2 = new EasyZip();
zip2.zipFolder('./downloads/'+application._id,function(){
zip2.writeToFile('./downloads/'+application._id+'.zip');
res.setHeader('Content-disposition', 'attachment; filename='+application._id+'.zip');
res.setHeader('Content-type', 'application/zip');
var fs = require('fs');
var filestream = fs.createReadStream('./downloads/'+application._id+'.zip');
filestream.pipe(res);
});
});
My angular.js code
$http.post('/download/archive/' + stateParams._id, {year: year}).success(function (data) {
var file = new Blob([data], {type: 'application/zip'});
console.log(file)
saveAs(file, 'application.zip');
});
Please help me to solve these. Thanks in advance.
Upvotes: 3
Views: 229
Reputation: 985
Even I had the same problem and was able to solve it. For more details check: Zip generated by EasyZip is not working properly Hope that this may help you.
Upvotes: 2