Uploading Files in AWS S3 Bucket Through JavaScript SDK
Create an S3 bucket from the Amazon S3 console page to upload the files in the AWS S3 bucket through JavaScript SDK:
Configure the S3 bucket by providing the bucket name and AWS region to create it:
Uncheck the box for blocking all public access and check the box for acknowledgment of these configurations:
Scroll down to the bottom of the page and click on the “Create bucket” button:
Click here to get the code for uploading files in the AWS S3 bucket and open the “.env” file to provide the credentials mentioned in the following screenshot:
After that, open the Terminal from the VS code inside the “app.js” file:
Type the following command to install dependencies:
Running the above command will install the npm dependencies:
After that, run the following command to run the application:
The above command will start the application
Download the Postman application by clicking here to upload the files using SDK:
On the app, perform the following steps:
- Select POST and type the http://localhost:3001/upload URL
- Select the Body option
- Select form-data
- Type the file name and select the file from the system
- Click on the “Send” button
Head onto the AWS S3 bucket page and verify it the file has been uploaded:
You have successfully uploaded the files in the AWS S3 bucket through JavaScript SDK.
Conclusion
To upload files in the AWS S3 bucket through JavaScript SDK, create an S3 bucket from the console page by providing a unique name with the region. After that, create the code files in JavaScript to upload the files in the Amazon S3 bucket. Download the Postman application, select POST, and provide the URL to upload files in AWS.