Before you begin
- An Express application deployed on Sevalla, as in Deploy Express.
- Node.js 20 or later in the application, which the AWS SDK for JavaScript (
@aws-sdk/client-s3) needs. The Express guide pins Node.js 24.
Create a bucket
In the sidebar, click Object storage, then click Create object storage. Enterstorefront-media as the Name, choose the Location closest to the application, and click Create object storage. See Create a bucket for every field.
Add the bucket details to the application
1
Copy the values
On the bucket’s Settings tab, copy the Endpoint and Bucket name under Details, and the Access key and Secret key under Access keys.
2
Add them as environment variables
On the application’s Environment variables tab, click Add environment variables. Add these variables, keep Available during runtime selected, and click Add environment variables:
They apply at the next deployment.
Install the AWS SDK
@aws-sdk/client-s3sends the S3 requests.@aws-sdk/lib-storagestreams uploads and splits large files into parts.@aws-sdk/s3-request-presignercreates presigned URLs.
Create the client
Create one client for the whole application:storage.js
auto. The two WHEN_REQUIRED options stop the SDK from adding checksums that only some operations need: without them, it signs the checksum of an empty body into presigned upload URLs, and R2 rejects the real upload.
Add routes for files
Add three routes toserver.js: one that streams an upload into the bucket, one that lists the files, and one that redirects to a presigned URL for a file:
server.js
export S3_ENDPOINT=...), run npm start, and upload a file with the curl command in Deploy and verify, using http://localhost:3000.
Deploy and verify
Commit and push the changes. With auto-deploy on, the push starts a deployment; otherwise, start one with Deploy now on the application’s Overview tab. When the deployment’s status changes to Deployed:-
Upload a file to the application’s domain:
The response is
{"key":"uploads/logo.png"}. -
Open
https://storefront-x7k2m.sevalla.app/files/logo.pngin a browser. The application redirects to a presigned URL on the bucket’s endpoint, and the image opens. -
On the bucket’s Objects tab, open the
uploadsfolder.logo.pngis there.
S3_BUCKET instead of the Bucket name.
Let browsers upload directly
Uploads that pass through the application use its bandwidth and memory. To let the browser send a file straight to the bucket, create a presigned URL forPutObjectCommand on the server and give it to the browser, and add a CORS rule to the bucket for your site’s origin. See Share files with presigned URLs.