jszip
jszip copied to clipboard
Can't use ReadableStream from generateNodeStream in the PutObjectCommand of s3
I was trying to create a zip and upload it to the s3 bucket using v3 sdk.
const zip = new JSZip();
fileArr.forEach((file: string) => {
zip.folder("./")?.file(file, fs.readFileSync(path.join(reportDir, file)));
});
const content: NodeJS.ReadableStream = zip.generateNodeStream({
type: "nodebuffer",
streamFiles: true
});
try {
const uploadCommand = new PutObjectCommand({
Bucket: config.S3_REPORT_DOWNLOAD_BUCKET,
Key: zipFile,
Body: content
});
data = await s3ClientUpload.send(uploadCommand);
console.log("ZIP file uploaded to S3");
} catch (error) {
console.log(error);
}
Here we are using content in the Body parameter of PutObjectCommand but it fails to recognize the readstream.