1

I'm currently using the jszip, jszip-utils, and FileSaver to zip and download several PDFs.

self.createZip = function () {
    var docs = self.list.filteredItems();
    var zip = new JSZip();
    var count = 0;
    var zipFilename = "zipFilename.zip";

    docs.forEach(function (item) {
        var filename = item.formDesc() + "_" + item.id() + ".pdf";
        // loading a file and add it in a zip file
        JSZipUtils.getBinaryContent('../career/document/StreamFile/?path=' + item.fileName(), function (err, data) {
            if (err) {
                throw err; // or handle the error
            }
            zip.file(filename, data, { binary: true });
            count++;
            if (count == docs.length) {
                zip.generateAsync({ type: 'blob' }).then(function (content) {
                     try {
                             saveAs(content, zipFilename);
                        } catch (e) {
                            console.log(e);
                        }                   
                });                
            }
        });
    });

This function currently works on all latest browsers except IE11. In IE11 is gets all the files, but Hangs on saveAs.

capiono
  • 2,875
  • 10
  • 40
  • 76
  • 1
    That's a good first step, but you are not at a point where posting to Stackoverflow makes sense yet. First, do some debugging: where does the code stop working between browser versions, is this a known issue for filesaver (did you look at their bug tracker?), are there any console errors that you can use to do some google searching, etc.? Right now all you're saying is "my code doesn't work, here it is, please go figure it out for me", without any signs that [you first tried to find out what might be wrong, yourself](/help/how-to-ask). – Mike 'Pomax' Kamermans Sep 08 '17 at 16:43
  • Mike, I have done all of that, even added a try block, to catch any error, but there is no error. all similar issue I found suggested using type blob for IE11. like I said in the post, it hangs on SaveAs and does nothing. So, I posted here to see if anyone else has experienced this issue. – capiono Sep 08 '17 at 16:48
  • Given that claim, I assume you googled for something like "filesaverjs ie11", the first hit for which gives me https://stackoverflow.com/questions/39266801/saving-file-on-ie11-with-filesaver -- you don't mention this in your post, and you don't mention whether its solution doesn't work for you. If it does: this question didn't need posting. If it doesn't, that is information people here need to know about because that makes your problem genuinely different from one already answered (several times from what I can tell by searching) on Stackoverflow. – Mike 'Pomax' Kamermans Sep 08 '17 at 16:53
  • Possible duplicate of [Saving file on IE11 with FileSaver](https://stackoverflow.com/questions/39266801/saving-file-on-ie11-with-filesaver) – Rob Sep 08 '17 at 16:56

1 Answers1

2

Try the following after your SaveAs statement to clear the buffer

content = null;
Elena Maximova
  • 916
  • 1
  • 8
  • 15