I have a function that currently uploads several images and saves them to a userβs download folder (works only in Chrome)
I want to transfer this function to the next step and put these images in one zip file.
Below is an example of my current code. I want to combine my code with the JSZip API, which I found here .
I already installed bower for this JSZip API and included the script in my html.
Here is my code that works great when loading multiple images at once:
$scope.downloadPhotos = function() { var photoUrls = []; for (var x = 0; x < $scope.$parent.photos.length; x++) { var p = $scope.$parent.photos[x]; if (p.isChecked) { photoUrls.push($scope.bucketUrl() + p.photoUrl); } } saveImage(photoUrls); }; function saveImage(urls) { var link = document.createElement('a'); link.setAttribute('download', null); link.style.display = 'none'; document.body.appendChild(link); for (var i = 0; i < urls.length; i++) { link.setAttribute('href', urls[i]); link.click(); } document.body.removeChild(link); }
And here is a sample JSZip API code for creating a zip file with the contents in it:
function create_zip() { var zip = new JSZip(); zip.add("hello1.txt", "Hello First World\n"); zip.add("hello2.txt", "Hello Second World\n"); content = zip.generate(); location.href = "data:application/zip;base64," + content; }
Now I'm just wondering how to combine these two images into a zip file. Thanks for your help!
source share