Page 1 of 1

How to upload to S3 with NestJS

Posted: Sun Feb 02, 2025 3:55 am
by monira444
In the previous article, we learned how to create an application that uploads files locally. However, in a real application, these files must be accessed remotely. Therefore, we can use several available services for storing static files. In this article, we will learn how to use one of the main services in this category: Amazon's S3. If you have no knowledge about S3, I suggest reading the article “ What is AWS S3 ”, where its advantages and limitations are explained in more detail.

Node.js - Fundamentals
Course
Node.js - FundamentalsKnow the course

Creating an AWS S3 account
Now let's get down to business. We need to register on the website , and it's worth noting that right on the home page you can get information about offers and free trials. For this article, we'll use the free S3 offer.

AWS Home Page

Once you access the website, we will create an account by chinese america data clicking on “Create an AWS Account” in the top right corner. On the next page, you will be asked to provide an email address for the account and the name of the AWS account.

AWS Registration Form

During this registration, Amazon will ask for a series of information, including the need for a credit card, as this is how Amazon validates that you are a real person who is registering. However, we will only be using the free offer and nothing will be charged to your card, but it is always important to be aware of any charges that may occur and ensure that you are following the limitations of the free offer, as these rules may change over time.

After registering, we will have access to the panel where we can search for the service name in the search bar. In this case, we will search for S3 and then click on the search result.

Locating S3 in the AWS Dashboard

Creating bucket
Now we must create a bucket, this is the term used by S3, it is basically a way of defining and organizing the files that will be stored in S3, for example we can have several buckets for certain different applications in the same S3 account.

Creating a bucket in S3

In the next step, we will configure this new bucket as follows:

Bucket name : in this field, we must enter the name of the bucket, remembering that it must be unique and globally exclusive. For this example, I will create it with the name “article-tw-s3”. However, you must create another name, since, as mentioned before, it needs to be globally unique.
AWS Region: In this field, we will select the closest region. Since I am from São Paulo, I will select the option “South America (São Paulo) sa-east-1”.
Block public access settings for this bucket : In this option, we will allow public access to the files. For this example, we will leave the files as public, as they can be accessed by anyone via the web. I would like to point out that they will be public for reading only . We must also select the “checkbox” just below, in the option “Disable blocking of all public access…”.
new bucket registration

Nest.js - Fundamentals
Course
Nest.js - FundamentalsKnow the course

Public Bucket Lock Option

The other options don't need to be changed, we'll leave them as default. Finally, the bucket will be created successfully: