Stuk / jszip

Create, read and edit .zip files with Javascript
https://stuk.github.io/jszip/
Other
9.77k stars 1.3k forks source link

Can't use ReadableStream from generateNodeStream in the PutObjectCommand of s3 #918

Open palashCItobuz opened 8 months ago

palashCItobuz commented 8 months ago

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.