figured I would share my solution, as i've seen alot of questions about this, but not many helpful answers.

using JSZip: https://stuk.github.io/jszip/

using saveAs from fileSaver.js: https://github.com/eligrey/FileSaver.js

First: it loops through downloading each file individually from s3, creates a blob, and puts each blob/file into a "folder".

Second: after each file has been downloaded from s3, it will then use the saveAs method to download/save the zipped folder.

function NewEditInfo(props) {
const [job, setJob] = useState([]);
const [imagesUploaded, setImagesUploaded] = useState(null); 

//initialize jsZip
var JSZip = require("jszip");
let zip = new JSZip();
let photoZip = zip.folder(`${job.streetAddress}`);

useEffect(() => { 
     //// API call to load job info from dynamo db
  function loadJob() {
    return API.get("api name", "/tablename/tableinfo", {
  'queryStringParameters': {jobId: props.match.params.id}    
   }); 
  } 
   /// onload function to load job info and get a count of files
    async function onLoad() {   

      try {
        const job = await loadJob();
        setJob(job[0])

        const ImagesUploaded = await Storage.list(`${job[0].jobId}`);
        setImagesUploaded(ImagesUploaded);

        } catch (e) {
          alert(e);
      }

    }

    onLoad();
  }, [props.match.params.id,]);


  /// On download button click, loop through / download images using the key given from storage.list in onload function
  async function handleDownloadClick(event) {
         event.preventDefault();    
      const imagesAsArray = [...imagesUploaded];

    for (let i = 0; i < imagesAsArray.length; i++) {                                                                                          
      await DownloadFileFromS3(imagesAsArray[i]); 
        }
       /// waits for "await DownloadFileFromS3, then executes the save as which saves the zipped folder created in "DownloadFileFromS3"
        zip.generateAsync({type:"blob"})
             .then(function(content) {
        saveAs(content, `${job.streetAddress}`);
        });
   }


    /// download each file from s3 and put it in the zip folder
    async function DownloadFileFromS3(fileToDownload) {

        const result = await Storage.get(fileToDownload.key, {download: true})

        let mimeType = result.ContentType
        let fileName = fileToDownload.key
        let blob = new Blob([result.Body], {type: mimeType})

        photoZip.file(fileName[1], blob)

   }

 return(

      <IonPage>
      <IonHeader>
        <IonToolbar>
      <IonButtons slot="start">
          <IonBackButton/>
      </IonButtons>
          <IonTitle>Download Images</IonTitle>
        </IonToolbar>
      </IonHeader>  
      <IonContent className="ion-padding">   
      <IonButton onclick={handleDownloadClick}> download </IonButton>
      </IonContent>
      </IonPage>
    );


  }


export default withRouter(NewEditInfo);
Answer from Jordan Spackman on Stack Overflow
Top answer
1 of 1
6

figured I would share my solution, as i've seen alot of questions about this, but not many helpful answers.

using JSZip: https://stuk.github.io/jszip/

using saveAs from fileSaver.js: https://github.com/eligrey/FileSaver.js

First: it loops through downloading each file individually from s3, creates a blob, and puts each blob/file into a "folder".

Second: after each file has been downloaded from s3, it will then use the saveAs method to download/save the zipped folder.

function NewEditInfo(props) {
const [job, setJob] = useState([]);
const [imagesUploaded, setImagesUploaded] = useState(null); 

//initialize jsZip
var JSZip = require("jszip");
let zip = new JSZip();
let photoZip = zip.folder(`${job.streetAddress}`);

useEffect(() => { 
     //// API call to load job info from dynamo db
  function loadJob() {
    return API.get("api name", "/tablename/tableinfo", {
  'queryStringParameters': {jobId: props.match.params.id}    
   }); 
  } 
   /// onload function to load job info and get a count of files
    async function onLoad() {   

      try {
        const job = await loadJob();
        setJob(job[0])

        const ImagesUploaded = await Storage.list(`${job[0].jobId}`);
        setImagesUploaded(ImagesUploaded);

        } catch (e) {
          alert(e);
      }

    }

    onLoad();
  }, [props.match.params.id,]);


  /// On download button click, loop through / download images using the key given from storage.list in onload function
  async function handleDownloadClick(event) {
         event.preventDefault();    
      const imagesAsArray = [...imagesUploaded];

    for (let i = 0; i < imagesAsArray.length; i++) {                                                                                          
      await DownloadFileFromS3(imagesAsArray[i]); 
        }
       /// waits for "await DownloadFileFromS3, then executes the save as which saves the zipped folder created in "DownloadFileFromS3"
        zip.generateAsync({type:"blob"})
             .then(function(content) {
        saveAs(content, `${job.streetAddress}`);
        });
   }


    /// download each file from s3 and put it in the zip folder
    async function DownloadFileFromS3(fileToDownload) {

        const result = await Storage.get(fileToDownload.key, {download: true})

        let mimeType = result.ContentType
        let fileName = fileToDownload.key
        let blob = new Blob([result.Body], {type: mimeType})

        photoZip.file(fileName[1], blob)

   }

 return(

      <IonPage>
      <IonHeader>
        <IonToolbar>
      <IonButtons slot="start">
          <IonBackButton/>
      </IonButtons>
          <IonTitle>Download Images</IonTitle>
        </IonToolbar>
      </IonHeader>  
      <IonContent className="ion-padding">   
      <IonButton onclick={handleDownloadClick}> download </IonButton>
      </IonContent>
      </IonPage>
    );


  }


export default withRouter(NewEditInfo);
🌐
GitHub
gist.github.com › c4software › 981661f1f826ad34c2a5dc11070add0f
Download multiple files then compress to one zip file using JSZip & JSZip-utils · GitHub
Uncaught Error: InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). I`m using react js and having this issue.can you please help? @Ugoivy @mkilponen ... @Ugoivy just a little improvement so you don't have to iterate twice over the urls, just take the url file name inside the forEach · import JSZip from 'jszip'; import JSZipUtils from 'jszip-utils'; import saveAs from 'save-as'; function test() { const urls = [ 'https://www..../Cani-spiaggia.png', 'https://www..../3
Discussions

Download a zip file in reactjs without any plugins - Stack Overflow
But the downloaded gz file was not able to open (seems to be corrupted). can some one help me with downloading zip file in reactjs. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - React-tsx-Download Multiple image file in Zip format - Stack Overflow
I want to download zip which contains the multiple images, I use the js-zip but it does not allow me to use jszip-util its show Can not find name JSZipUtils for that because of my TSX file i think. here is some code which I tried.. import * as React from 'react'; import JSZip from 'jszip'; ... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Download and zip files in React? - Stack Overflow
Is it possible to download files from a server and then zip it on the client side using JSZip? ... How to add multiple Windows 11 users that have umlauts (Ä, Ö, Å, etc.) in them into groups that have umlauts in them via PS1 PowerShell script? Are there specific limits, of what percentage and above is considered as ... More on stackoverflow.com
🌐 stackoverflow.com
Download single file as pdf and multiple files as zip using axios in React
Is there any way i can change it so that if the single file is there it will be downloaded as it is and for multiple files they are downloaded as Zip file? More on stackoverflow.com
🌐 stackoverflow.com
September 21, 2020
🌐
Medium
yashodgayashan.medium.com › zip-files-in-react-30fb77fd6a58
Zip files in React. In this tutorial we will go through how… | by Yashod Perera | Medium
November 3, 2020 - <input multiple type="file" name="file" onChange={this.onChangeFile}/> Then let’s implement the onChangeFile method to zip the inputed files. First we have to install the npm package. ... For the zip functionality you have to use following function. ... Then to generate the completed zip file. zip.generateAsync({type: "blob}) .then(content => { // code });
🌐
GitHub
github.com › Ishaan28malik › react-zip-download
GitHub - Ishaan28malik/react-zip-download: A project to implement multi file zip downloader using Reactjs
A project to implement multi file zip downloader using Reactjs - Ishaan28malik/react-zip-download
Starred by 6 users
Forked by 5 users
Languages   HTML 64.0% | CSS 26.7% | JavaScript 9.3% | HTML 64.0% | CSS 26.7% | JavaScript 9.3%
🌐
Medium
shubhamjain-84217.medium.com › downloading-multiple-files-with-react-42706b0e765c
Downloading multiple files with React | by Shubham Jain | Medium
March 24, 2021 - so we make a Downloader component and will render this component with the files as a prop conditionally on user action. This solves the cons we faced with the first solution but I am not sure if this is the best solution out there considering the reputation of iframes, sharing some links which might help you to decide whether to go for this solution: ... A better solution could be to have a single downloadable URL generated after zipping all your files at the backend and use that instead to avoid loading too many iframes in your current window or avoiding the cons of the first solution.
🌐
Filestack
blog.filestack.com › home › generate a zip file with javascript & react – filestack
Generate a Zip File With Javascript & React - Filestack
April 12, 2019 - The pictures uploaded in the sample app can be downloaded as well. To do so we used the zip process API of Filestack. ... Implementing this in React is very simple to achieve.
🌐
Medium
medium.com › @kuldeepkrsharma00 › how-to-zip-a-file-and-upload-using-react-a-step-by-step-guide-2f3cf18f5b41
How to Zip a File and upload using React: A Step-by-Step Guide | by Kuldeepkrsharma | Medium
January 25, 2024 - One popular choice is jszip. You can install it using npm: ... Additionally, create state variables selectedFiles and zippedFile to manage the selection of multiple files and the resultant zipped file:
🌐
JSFiddle
jsfiddle.net › Victornpb › b78wbaL8
download multiple files and save as zip bundle - JSFiddle - Code Playground
September 21, 2023 - Click Create new key, fill "JSFiddle" as the name for the API key, and save.
Find elsewhere
🌐
YouTube
youtube.com › watch
Easily Zip Files in React - YouTube
Learn how to generate ZIP archives to download multiple files on the fly with JavaScript in React using JSZip and Next.js API Routes.We'll walk through creat...
Published   September 21, 2023
🌐
CodeSandbox
codesandbox.io › s › download-multiple-images-as-a-zip-with-jszip-file-saver-and-reactjs-iykufe
Download multiple images as a zip with jsZip, file-saver and Reactjs - CodeSandbox
September 28, 2023 - Download multiple images as a zip with jsZip, file-saver and Reactjs by ทíทó using file-saver, jszip, jszip-utils, react, react-dom, react-scripts
Published   Oct 03, 2022
Author   ทíทó
🌐
StackBlitz
stackblitz.com › edit › zip-file-downloader-react
Zip File Downloader React - StackBlitz
Starter project for React apps that exports to the create-react-app CLI.
🌐
DEV Community
dev.to › jaydeepkhachariya › how-make-zip-of-images-and-download-it-using-react-js-in-3-easy-steps-lkb
How make zip of images and download it using React JS in 3 Easy steps - DEV Community
January 27, 2023 - import { useState, useCallback } from "react"; import JSZip from "jszip"; export default Download(){ const [images,setImages]=useState([ // Array of images "image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", ]) const zip = new JSZip(); // instance of JSZip // Function for make zip file and download it async function handleZip(){ // Add Images to the zip file for (var i = 0; i < images.length; i++) { const response = await fetch(images[i]); const blob = await response.blob(); console.log(blob); zip.file(images[i].split("/").pop(), blob); if (i == selectedImages.length - 1) { /
🌐
Stack Overflow
stackoverflow.com › questions › 58143424 › react-tsx-download-multiple-image-file-in-zip-format
reactjs - React-tsx-Download Multiple image file in Zip format - Stack Overflow
JSZipUtils.getBinaryContent(url, function (err, data) { if (err) { throw err; } zip.file(filename, data, { binary: true }); it works very well because jszip-utils module is not available in typescript i think I am not sure, so it is the alternate ...
🌐
Mridul
mridul.tech › home › blogs › how to generate zip with file links in next js and react js
How to Generate ZIP with File Links in Next JS and React JS
December 2, 2023 - Also Read: 10 React Project Ideas to Boost Your Portfolio · 5. Now let’s fetch the file URLs and get the files. We will map over the array and fetch each file from the object. And we can also name the files different name as well. // /pages/index.js import JSZip from "jszip"; const zip = new JSZip(); const remoteZips = files.map(async (file) => { const response = await fetch(file.url); const data = await response.blob(); zip.file(`${file.name}.${file.type}`, data); return data; });
🌐
Medium
medium.com › twodigits › multi-file-download-using-javascript-9b0b8a14639b
Multi-File-Download using JavaScript | by Robert Diers | NEW IT Engineering | Medium
July 21, 2022 - Multi-File-Download using JavaScript “Please create a ZIP for us, so we can download with 1 click.” — I think nearly every developer has heard something like this a lot of times. But times …
🌐
npm
npmjs.com › package › multiple-downloads-one-zip
multiple-downloads-one-zip - npm
May 17, 2020 - // require the module let download = require('multiple-downloads-one-zip') // Urls where files are downloaded from let urls = [ "http://i996.imggur.net/hunter-x-hunter/390/hunter-x-hunter-11553019.jpg", "http://i996.imggur.net/hunter-x-hunter/390/hunter-x-hunter-11553025.jpg", ] let zip_name = "myZip" // avoid spaces let zip_dir = "." // give an existing directory // download and zip the files // Since it is an async function, we must put `await` before, and the function must be called in an `async` function await download.downloadAndZip(urls,{ zip_name: zip_name, zip_dir: zip_dir, onEnd: (data) => { // do what we want with the data containing the zip path }, onFileComplete: (data) => { // do what we want } }) none ·
      » npm install multiple-downloads-one-zip
    
🌐
YouTube
youtube.com › watch
Multiple Images to Zip File Download | JavaScript Tutorial - YouTube
‍🎓 NEW: Earn a professional certificate in web development from Meta Inc. (course links in card below) 👇⚡ Need hosting for a website, WordPress blog or Nod...
Published   April 11, 2020
🌐
Stack Overflow
stackoverflow.com › questions › 63989778 › download-single-file-as-pdf-and-multiple-files-as-zip-using-axios-in-react
Download single file as pdf and multiple files as zip using axios in React
September 21, 2020 - try { const res = await axios.get( `${apilink}/download/`, { responseType: "blob", params: body, } ); const url = window.URL.createObjectURL(new Blob([res.data])); const link = document.createElement("a"); link.href = url; link.setAttribute("download", "file.zip"); document.body.appendChild(link); link.click(); } catch (e) { toaster.notify("Cannot Download.Please try again"); } I am currently using this method to download files coming from the API. But here whether the file is single or multiple files they are being downloaded as Zip.