Skip to main content
If your project uses the uploads module, you need to decide where files live in production before the first upload. The module doesn’t move files between providers, so switching later means migrating them yourself. The module stores files wherever STORAGE_PROVIDER points:
  • local (default): a directory on the server’s disk;
  • s3: any S3-compatible object storage.
Either way, files are always served through the app at GET /api/uploads/<id>, never directly from storage, so the bucket can stay private.

Choose a location

Recommendation: on Railway, use a Railway Bucket. Use a volume only for a simple single-instance deploy. On your own infrastructure, use S3-compatible storage if you might ever run more than one instance.

What production enforces

With NODE_ENV=production (always true in the Docker image), the startup env check refuses configurations that would lose files: “On Railway” means RAILWAY_ENVIRONMENT_ID is set; Railway sets it for you. Any of these errors makes the server exit with code 1 at startup. The kit can’t check whether a directory actually survives a redeploy; that is up to you.

Railway Bucket

1

Create the bucket

Add a bucket to your Railway project and pick its region. You can’t change the region later. The real bucket name is the display name plus a short hash, for example my-bucket-jdhhd8oe18xi.
2

Reference its variables from the app service

Replace <bucket> with the bucket’s name in the project:
3

Leave path-style off

Don’t set S3_FORCE_PATH_STYLE. Railway Buckets use virtual-hosted addressing (bucket name in the hostname). Only buckets created before Railway switched to this style may need S3_FORCE_PATH_STYLE=true.

Railway volume

1

Attach a volume

Attach a volume to the app service with mount path /app/volumes/uploads. The image creates that directory for the nextjs user.
2

Leave the path unset

Don’t set STORAGE_LOCAL_PATH, and leave STORAGE_PROVIDER unset or local. Railway sets RAILWAY_VOLUME_MOUNT_PATH on a service with a volume, and the module uses it as the storage directory. If you do set STORAGE_LOCAL_PATH, it must point inside the volume.
3

Grant write access

Set RAILWAY_RUN_UID=0. Railway documents permission issues for images that run as a non-root user (here nextjs, UID 1001) on mounted volumes; this variable runs the process as root.
A Railway service can have only one volume, a service with a volume can’t have replicas, and each redeploy causes a short downtime. If you expect to scale out, use a bucket.

Your own server

Local disk

The image sets NODE_ENV=production, so local outside Railway needs an absolute STORAGE_LOCAL_PATH. Mount a persistent volume at the directory the image prepares:
Permissions matter because the process runs as nextjs (UID 1001):
  • A new, empty named volume mounted at /app/volumes/uploads inherits the directory’s ownership from the image, so nextjs can write to it.
  • A named volume mounted at a path the image doesn’t prepare fails with Permission denied.
  • A reused volume whose files belong to root keeps its owner, and the first upload fails with 500 storage_failed. Fix the ownership with chown -R 1001:1001.
  • A host directory (-v /srv/uploads:/app/volumes/uploads) must be writable by UID 1001.
Back up the directory yourself. Running more than one instance requires s3.

S3-compatible storage

Any S3-compatible service works: AWS S3, Cloudflare R2, MinIO, Backblaze B2 and others.
Take credentials from your provider, not from .env.example. The sample values (minioadmin, http://localhost:9000) are for the local MinIO, and validation doesn’t reject them. A region or addressing style that’s well-formed but wrong for your provider only fails on the first upload, with 500 storage_failed.

Local development

Locally, .env.example uses local with ./volumes/uploads. To try the S3 path, start MinIO with the s3 Compose profile; it creates the <slug>-uploads bucket for you:
Then set STORAGE_PROVIDER=s3 in .env. MinIO is for development and CI only; it isn’t part of the production image.

Uploads module

What the module does and how to use it in features.

Deploy on Railway

The full Railway setup.