I am developing a REST API using express that includes an image upload.
I need to get the image file data as a stream and then pipe that stream to s3 bucket. (As the image files may be very large to fit into memory and I want it to be directly move into s3 bucket).
I created the image downloading route properly as follows:
router.get('/', (req, res) => {
let image_key = "shop/ER-2.jpeg";
let read_stream = s3.getObject({
Bucket: process.env.AWS_S3_BUCKET,
Key: image_key,
}
).createReadStream();
read_stream.on('close', () => {
res.end()
});
read_stream.on('error', () => {
res.status(502).end();
});
read_stream.pipe(res);
});
But I can't understand how to pipe(OR get a read stream) from the request object when uploading a file from req.files. Thanks for help in advance.