Amazon s3 bucket image upload using node.js
In this article, I will explain about storing the image in S3 bucket and save URL in your local storage.

Before we move to write we have to create an S3 bucket. The link helps you to create a bucket. Click here
Once you create a bucket then move to write coding.
In AWS account, you have these things
- AWS_ACCESS_KEY_ID,
2. AWS_SECRET_ACCESS_KEY
3. Bucket name
4. Region
Various ways we can store images in the S3 bucket. In this example, we store images using base64 format.
Convert base64 to image buffer.

AWS-SDK
Install plugin
npm install aws-sdk
Once you installed successfully then move to set up AWS-SDK.

Set your ‘AWS_ACCESS_KEY_ID’ and ‘AWS_SECRET_ACCESS_KEY’ in your .env file.
Set your region and bucket name from your AWS account.
PutObject function

In the above picture we define these things
key: Path of images (‘/user/1.jpg’).
buffer: Image buffer.
ContentEncoding: 'base64',
ContentType: 'image/jpeg',
ACL: 'public-read'
S3Url:
We can set our uploaded image URL
You can access your image by using:
https://s3.amazonaws.com/bucketname/foldername/imagename.jpg
or if there are no folders, you can do:
https://s3.amazonaws.com/bucketname/imagename.jpg
Get uploaded image URL:

The function return image URL.
Once you get image URL then store in your local storage.
Once I get the image URL then I store the image URL in my PostgreSQL DB.
Thank you for reading.
Have a nice day!