通过EasyZip产生邮编工作不正常不正常、邮编、工作、EasyZip

2023-09-14 00:11:30 作者:帅界扛把子

我一直在使用Easyzip生成一个zip文件。我可以直接从下载folder.But打开它时,试图下载,我收到此错误后打开它: - '发生错误而解压文件

I have generated a zip file using Easyzip. I can open it directly from download folder.But when try to open it after downloading, I am getting this error:- 'error occurred while extracting files'.

这我的后端code: -

This my backend 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);
    });
});

我angular.js code

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.

推荐答案

我有同样的问题,并能够通过使用来解决它:{responseTyp的:arraybuffer'}在$ http.post()请求。有关详细信息查询:如何使用下载的zip文件角以及AngularJS:显示BLOB(.PDF)在角应用

I had the same problem and was able to solve it by using: {responseType:'arraybuffer'} in the $http.post() request. For more details check: how to download a zip file using angular as well as AngularJS: Display blob (.pdf) in an angular app