npm install jszip
npm install file-saver
import JSZip from 'jszip';
import { saveAs } from 'file-saver'; // Install if needed: npm install file-saver
const handleCompressAndDownload = async () => {
if( resizedFiles.length ===0) return;
const zip = new JSZip();
for (const file of resizedFiles) {
const response = await fetch(file.src);
const data = await response.blob();
zip.file(file.name, data, { binary: true });
}
try {
const content = await zip.generateAsync({ type: 'blob' });
saveAs(content, 'compressed_files.zip');
} catch (error) {
console.error('Error zipping files:', error);
}
};
<button onClick={handleCompressAndDownload}>Compress and Download</button>