I was reminded of this question .. since there is no answer yet, I am writing a possible solution if it can be useful to someone else:
- as said, the first problem is related to the transfer of blob url to jszip (it does not support blobs, but also does not cause any error to notify about it, and it successfully generates archive of damaged files): to fix this, simply go through the base64 data line instead of the object url blob;
- The second problem is the synchronization of file names: the easiest way is to download one file at a time, rather than using parallels xhr queries.
So, the modified top code could be:
var fileURLs = ['http://www.test.com/img.jpg',...]; var zip = new JSZip(); var count = 0; downloadFile(fileURLs[count], onDownloadComplete); function downloadFile(url, onSuccess) { var xhr = new XMLHttpRequest(); xhr.onprogress = calculateAndUpdateProgress; xhr.open('GET', url, true); xhr.responseType = "blob"; xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (onSuccess) onSuccess(xhr.response); } function onDownloadComplete(blobData){ if (count < fileURLs.length) { blobToBase64(blobData, function(binaryData){
Last note, this solution works very well if you upload several and small files (less than 1 MB in size as the size for less than 10 files), in other cases JSZip will cause the browser tab to fail when the archive is generated, so it is better to use a dedicated stream for compression (WebWorker, e.g. zip.js).
If after that the archive was generated, the browser still continues to crash with large files and without reporting any errors, try launching the saveAs window without sending binary data, but passing the blob link ( a.href = URL.createObjectURL(zippedBlobData); where zippedBlobData is a blob object that refers to the generated archive data);
guari source share