Based Tyrone
Based Tyrone

Reputation: 41

handling file uploads in Nodejs with AWS

I have a server in Node.js and say I have a POST request that uploads a multipart file to my server and then I upload it to AWS S3.

The issue is, with multer, I have to save the file to disk first.

If I deploy my server onto EC2 then how will file uploading work as it won't have a destination to temporarily store the file?

Thanks!

Upvotes: 0

Views: 245

Answers (1)

Andy Gaskell
Andy Gaskell

Reputation: 31761

You can use streams with busboy. I don't have experience with the AWS Node SDK, but here's the general idea:

req.busboy.on('file', function (fieldname, file, filename) {
     const params = { Bucket: 'bucket', Key: 'key', Body: file };
     s3.upload(params, (err, data) => {
         console.log(err, data);
     });
});

Upvotes: 1

Related Questions