const archiver = require('archiver'); async function downloadS3FilesAsZip(res, bucket, keys) { const archive = archiver('zip', { zlib: { level: 5 } }); // Set headers for browser download res.attachment('download.zip'); archive.pipe(res); for (const key of keys) { const command = new GetObjectCommand({ Bucket: bucket, Key: key }); const response = await s3Client.send(command); // Append the S3 body stream to the archive archive.append(response.Body, { name: key.split('/').pop() }); } await archive.finalize(); } Use code with caution. Best Practices and Considerations
: A popular Node.js package that can consume multiple streams and output a single ZIP stream. s3 download multiple files as zip nodejs
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3"); const s3Client = new S3Client({ region: "your-region" }); Use code with caution. 3. Create the Zipping Function const archiver = require('archiver')