How to upload image/file to AWS S3 bucket using nodejs

In this era amazon provides the best web services. So today i am going to explain how we can store data on AWS S3 bucket with help of nodejs. firstly after sign in on amazon website you need to follow these steps for upload data into S3 bucket.
1. Go to AWS console https://console.aws.amazon.com/s3/
2. Choose Create bucket.
3. Enter bucket name.
4. Select Region what you want to choose
5. Then bucket to make public.
6. Click on save
7. Now bucket created

Setup project for node js:

1 . mkdir node

2 .  cd /node

3 .  Run these commands for install node project

4. Now create index.js file in the root of the project folder. And paste this code.

5. Install ‘aws-sdk’ library for use AWS S3 bucket

6. After that add this code on top of page

7. This is AWS bucket details what you need to set in nodejs code.

This function i have created for upload file on aws s3 bucket. I use fs library for read file content and send file to the bucket with this code.

Call function in index.js file

Now run application with this command

This is tutorial for upload file from node application to AWS S3 bucket if you like this tutorial please share and keep learning for better life. Thanks, 🙂

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *