File storage
Presigned uploads to a private bucket on Cloudflare R2, Amazon S3 or Google Cloud Storage.
Requires:DatabaseEmailsSign-in and teams
Providers
Pick one to update the preview and filesList prices at the time of writing. Verify before you rely on them.
Preview
What it adds
7 things, working end to end- Direct browser uploads through short-lived presigned URLs: the app only stores metadata (StoredFile)
- Private buckets and authorized downloads, as a redirect to a presigned URL or streamed through the route
- One authorization choke point for upload, read and delete, with scopes that set size and type limits
- Server-generated object keys, and a check of the first bytes instead of trusting the Content-Type
- A files page with dropzone, upload progress, preview and delete
- The ai-attachments scope, so the AI chat can take attachments
- Provider contract tests that every provider must pass
Set up Cloudflare R2
Accounts and keys, in this order- 1Create a private bucketKeep it private: no public access, no custom domain, no r2.dev domain.dash.cloudflare.comR2Create bucket.envSTORAGE_PROVIDER=r2R2_BUCKET=R2_JURISDICTION=eu
- 2Create an API tokenObject Read & Write, limited to the bucket. Copy your account ID too.R2Manage API tokens.envR2_ACCOUNT_ID=R2_ACCESS_KEY_ID=R2_SECRET_ACCESS_KEY=
- 3Allow browser uploadsUploads go straight from the browser, so the bucket needs a CORS rule for your app origin: methods GET, PUT, HEAD; allowed header
content-type; exposeETag. Do not use a*allowed header. Paste this policy, with your own domain next to localhost:BucketSettingsCORS policyCORS policy[{"AllowedOrigins": ["http://localhost:3000","https://domain.com"],"AllowedMethods": ["GET","PUT","HEAD"],"AllowedHeaders": ["content-type"],"ExposeHeaders": ["ETag"],"MaxAgeSeconds": 3600}] - 4Create the tablesPush the Prisma schema, then start the app.npx prisma db push
Environment variables
For the selected provider.env
# r2, s3 or gcs
STORAGE_PROVIDER=
# redirect to a presigned URL, or stream through the route (optional)
STORAGE_DOWNLOAD_MODE=
# Presigned PUT lifetime in seconds (optional)
STORAGE_UPLOAD_URL_EXPIRES_IN=
# Presigned GET lifetime in seconds (optional)
STORAGE_DOWNLOAD_URL_EXPIRES_IN=
# Cloudflare account id
R2_ACCOUNT_ID=
# API token access key
R2_ACCESS_KEY_ID=
# API token secret
R2_SECRET_ACCESS_KEY=
# Bucket name
R2_BUCKET=
# eu or auto (optional)
R2_JURISDICTION=
Works with
Other modules this one connects toAdd it to your repo
Pick the preset in the builder, check the providers, and download a repo that already has this module wired in.
