1

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.

Rumesh Madhusanka
  • 1,105
  • 3
  • 12
  • 26
  • 1
    You do not handle the "req". So where is your upload? A good deal for uploading large files to S3 is the AWSUploadManager. Just hand out pre-signed urls and let the client connect directly to s3 -without piping through the backend. – nologin Apr 11 '20 at 07:27

0 Answers0