#174·jszip

cannot add multiple file onto zip

Author: onelazyugyCreated Sep 25, 2014Updated Sep 8, 2026
Labelsbug

I am using JSZip to generate a zip containing multiple files. The data is coming from the server in JSON format. I am only getting 2 files inside the for loop instead of multiple files. The size of the array of JSON is more than 2 so I expect multiple files not just 2.

javascript
    var zip = new JSZip();
    var root = data.list.dataList;
    var length = root.length;
    var i;
    for(i = 0; i < length; i++){                                                    
    var aFileName = "a_"+ root[i].type + "_" + root[i].orderNumber + ".xml";//just the name of the file                         
    var aContent = root[i].content; //content of file                               

    var bFileName = "b_"+ root[i].type + "_" + root[i].orderNumber + ".xml";//just the name of the file         
    var bContent = root[i].content; //content of file   

    //put files onto a folder
    zip.folder("Folder Name").file(aFileName, aContent).file(bFileName, bContent); 
   }
   //generate the zip with all files
   var content = zip.generate();
   location.href="data:application/zip;base64," + content; 

can someone please suggest a solution or an example similar to this since this code only take the content of the last iterations. This is why I can only get 2 files instead of multiple files