Add file uploads with object storage
This guide adds file uploads to a Next.js app with Naijacloud object storage. At the end, files people upload are saved to a private bucket in af-west (Port Harcourt) or eu-west (Europe), and listed back with signed links that expire after an hour, using the standard AWS SDK for JavaScript against our S3-compatible endpoint. The stack is Next.js 16 and @aws-sdk/client-s3; the same calls work from any language with an S3 client.
nextjss3An upload form in your app. Each file lands in a private bucket under uploads/, and the page lists them with links that only work for an hour.
Before you start
- A Next.js app deployed as a web service on Naijacloud, from a GitHub repository. Deploy Next.js with Postgres and Prisma gets you one; the database isn’t needed here.
- A Naijacloud account. Each workspace gets 5 GB of object storage free every month.
Create a private bucket
In the dashboard, open Object storage and click Create bucket. Give it a Bucket name (names are global, so make it yours, for example acme-uploads), choose the Region closest to your users and keep Access on Private. Click Create bucket.
Private means nothing in the bucket is readable without a signature. Your app hands out signed links instead, so you decide who sees each file.
Create an access key
Still in Object storage, open Access keys and click Create access key. Name it after the app that will use it, for example acme uploads, and click Create key.
Your new access key shows the Access Key ID and the Secret, and the endpoint for each region. Copy all three now: you won’t see the secret again.
Add the variables to your service
Open your web service, go to Variables and click Bulk edit. Add five lines, with your own values, then Save variables:
Use the endpoint and region your bucket is in: https://af.storage.naijacloud.app with af-west, or https://eu.storage.naijacloud.app with eu-west. The key works in every region the workspace stores data in.
Install the SDK and create a client
Receive uploads
A route handler takes the form post, writes the file to the bucket under a random prefix so names never collide, and sends the browser back to the list:
List files with signed links
The page lists what’s in uploads/ and signs a one-hour link for each file. await connection() keeps this at request time, so building the app never needs the bucket.
Deploy and upload a file
The push deploys. Open your app, choose a file and click Upload. It appears in the list; click it and the signed link opens the file. In the dashboard, the bucket’s page shows the same object under uploads/.