December 6, 2021

Things You Need To Know If You Want To Upload A File To S3 Nodejs

You might have some files that users have uploaded in the format of a form, or perhaps you are creating files, big or small, for the users to download. No matter what the case may be, you always require a safe place to keep these files.

There is one Amazon service called S3 that stores files. You might already be familiar with it since it’s an older service. From DOC files to PDFs, and ranging in size from 0B to 5TB, almost any file type can be stored here with proper security once you upload files to s3 nodeJS.

What is S3?

Amazon S3 is one of the great services provided by Amazon Web Services. You can add an S3 bucket to your AWS account if you already use it for other things. Traditionally, these files are stored on local disks, but cloud storage is far more convenient. Especially if we have to share a disk among multiple servers. 

Customers can use S3 to manage data for cost optimization, access control, and compliance with strict regulatory requirements. It provides comprehensive security and compliance capabilities that meet even the most stringent regulatory requirements. 

Simply put, S3, or Amazon Web Services Storage, is an object-based storage system, in which files you store are stored as objects rather than files. Dropbox is one of many companies that use S3, and there are, obviously, many other companies that use it. The recent move by Dropbox to save metadata to their own service is for them to save main data in S3. You might ask why? Well, S3 isn’t very expensive, and it is almost 99.9% uptime. Additionally, you can use services like Amazon S3 Glacier to store data for less than $0.01.

How To Upload Files To Amazon S3?

AWS accounts are automatically created if you already have one. If not, go to Amazon and create a new one. Obtain your AWS credentials by logging in to AWS, clicking your name at the top right, and then choosing “My Security Credentials.”

Ensure that “Programmatic access” is enabled on the sidebar by clicking “Users”.

Continue to the next screen by using the buttons at the bottom of the page (“Next: Permissions”). Click on “Attach existing policies directly” to display S3 policies. In the filter, type “S3” to display S3 policies. Creating an Amazon S3FullAccess user will give you the access key ID and secret access key. Include those in the .env file of your project, or keep them somewhere for future reference.

After that, go to the S3 homepage, enter a name, select an AWS region for creating a bucket.  Installation of the AWS-SDK package can be done with npm install AWS-SDK. Storage of your AWS access codes is done in the .env file.

You can now upload files by loading them from the storage device. With the console, you can also make certain files or buckets public based on your needs.

Leave a Reply

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