To pipe a stream to s3.upload() with Node.js, we call the stream.PassThrough constructor.
For instance, we write
const uploadFromStream = (s3) => {
const pass = new stream.PassThrough();
const params = { Bucket: BUCKET, Key: KEY, Body: pass };
s3.upload(params, (err, data) => {
console.log(err, data);
});
return pass;
};
inputStream.pipe(uploadFromStream(s3));
to define the uploadFromStream function.
In it, we create a PassThrough object.
Then we call upload with the params object to upload the stream data.
Next, we call pipe with the PassThrough object returned by uploadFromStream to upload the inputStream data.