Stuk / jszip

Create, read and edit .zip files with Javascript
https://stuk.github.io/jszip/
Other
9.8k stars 1.3k forks source link

pdf files from server get corrupted after creating zip #657

Open bhuisman1992 opened 4 years ago

bhuisman1992 commented 4 years ago

Hi there,

I've successfully created a zip file with a PDF init. But when i try to open the file it says the file is corrupted.

var zip = new JSZip();
        var count = 0;
        var zipFilename = "zipFilename.zip";

        var urls = [];
        var filenames = [];
        var groupHolder = $(target).closest('.group-downloads');
        var productDownloads = $(groupHolder).children('.group-single-download');

        $(productDownloads).each(function () {
            urls.push(($(this).data('downloadUrl')));
            filenames.push(($(this).data('filename')));
        });

        console.log(urls);

        $(urls).each(function(url){
            var filename = filenames[count];

            // loading a file and add it in a zip file
            JSZipUtils.getBinaryContent(url, function (err, data) {

                if(err) {
                    throw err; // or handle the error
                }

                zip.file(filename, data, {binary:true});
                count++;

                // Create zip if there are no more items left.
                if (count == urls.length) {

                    zip.generateAsync({type:'blob'}).then(function(content) {
                        saveAs(content, zipFilename);
                    });

                }

            });
        });

The PDF url on my server is: https://artiteq.local/wp-content/uploads/2019/05/ARTITEQ_IMAGINE-IT-_TECHNICAL-SHEET.pdf

Am i doing something wrong?

chjiyun commented 8 months ago

i also have this problem