Upload Files to Amazon S3 Using Node.js, Express, and AWS SDK v3

Learn to build a REST API with Node.js, Express, Multer, and AWS SDK v3 to upload files directly to Amazon S3. Step-by-step guide.

miércoles, 29 de julio de 2026 • 4 min read • Q2BSTUDIO Team

Tutorial: API REST para subir archivos a S3

File management in modern web applications goes far beyond a simple upload form. User profiles, electronic invoices, business reports, or multimedia content require scalable, secure, and high-performance storage solutions. Amazon S3 has become the de facto standard for cloud storage, and combining it with Node.js, Express, and the AWS SDK v3 allows building fast, reliable upload APIs aligned with best development practices.

In this article, we will explore how to implement a REST endpoint that receives files from a client and stores them directly in an S3 bucket, using Multer for multipart/form-data handling and the official AWS client for JavaScript. The approach is designed for developers looking to integrate this functionality into custom applications, whether an internal portal, a SaaS, or an e-commerce platform.

Before starting, make sure you have Node.js 18 or higher, an active AWS account, and an S3 bucket created in the desired region. You will also need an IAM user with programmatic access and appropriate permissions (at least s3:PutObject).

The initial setup of an Express project is quick. After initializing the package.json with npm init -y, we install the essential dependencies: express, multer, dotenv, uuid, and @aws-sdk/client-s3. The dotenv library allows us to manage environment variables such as the AWS region, credentials, and bucket name without exposing sensitive data in the source code.

The next step is to create the S3 client. With version 3 of the AWS SDK, instantiation is straightforward and typed. We define a new S3Client object, passing the region and credentials. This client will be used to send commands like PutObjectCommand, which is responsible for uploading the file to the bucket.

Multer is configured with memory storage, meaning the file is received as a buffer in the req.file object. This is the recommended option when forwarding the content to an external service like S3, avoiding temporary writes to the server's disk. The configuration is minimal: const upload = multer({ storage: multer.memoryStorage() }).

The POST /upload endpoint receives a 'file' field of type file. Inside the async handler, we generate a unique name with uuid to avoid collisions and preserve the original user's filename. Then we call s3.send with the PutObjectCommand, specifying bucket, key (file name), body (the buffer), and contentType (the file's MIME type).

The successful response returns a JSON with the generated name and a success indicator. In case of error, the exception is caught, and a 500 status with a generic message is returned. It is important to log the error server-side for debugging, but without exposing internal details to the client.

Once the server is running (npm start or node index.js), we can test the endpoint with Postman or any HTTP client. We send a POST request to https://localhost:3000/upload, select Body > form-data, add a 'file' key of type File, and choose a document or image. The response will contain the unique name with which it was stored in S3.

Common errors include AccessDenied (missing s3:PutObject permission in the IAM policy), NoSuchBucket (wrong bucket or region), and InvalidAccessKeyId (incorrect or rotated credentials). Always check the AWS IAM console and your bucket configuration.

Once basic upload works, possibilities multiply. You can add file type and size validation, upload multiple files with upload.array('files'), generate pre-signed URLs so users upload directly from the frontend without passing through your server, or use CloudFront to serve files with low latency. It is also advisable to organize files in virtual folders within the bucket using key prefixes (e.g., users/{id}/photos/profile.png).

From a business perspective, integrating S3 with Node.js fits perfectly into microservices architectures and cloud-native applications. At Q2BSTUDIO, we develop custom software that leverages the elasticity of AWS or Azure cloud to handle growing data volumes without compromising security. Cybersecurity is a fundamental pillar: each bucket must be configured with restricted access policies, encryption at rest and in transit, and periodic credential rotation.

Additionally, artificial intelligence can enhance the management of uploaded files. For example, integrating AI agents that automatically classify documents, extract metadata, or detect sensitive content before storage. At Q2BSTUDIO we also implement Business Intelligence solutions with Power BI that consume data from S3 to generate real-time dashboards, and automate ingestion and transformation processes with serverless pipelines.

If your project requires efficient and scalable file uploads, this technological combination is a safe bet. Remember that SDK v3 allows working with more modern data types and native promises, facilitating integration with async/await and debugging.

To delve deeper into building robust and secure software, we invite you to check our cloud AWS and Azure services, where we design infrastructures that support intensive storage and processing workloads. You can also explore how artificial intelligence and AI agents are transforming business automation with custom solutions.

In summary, uploading files to Amazon S3 with Node.js, Express, and AWS SDK v3 is a straightforward process that, when well implemented, brings scalability, security, and performance to any application. From user profiles to critical documents, this API allows you to externalize storage and focus on what really matters: your business logic.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.