Configuration
Configure storage providers and environment variables
Environment Variables
Add the following environment variables to your .env file:
# S3-Compatible Storage
S3_ACCESS_KEY="your-access-key"
S3_SECRET_KEY="your-secret-key"
S3_BUCKET="your-bucket-name"
S3_REGION="auto" # Use "auto" for Cloudflare R2
S3_ENDPOINT="https://your-endpoint.r2.cloudflarestorage.com"Cloudflare R2 Setup
Cloudflare R2 is a cost-effective S3-compatible storage option.
Steps
- Create an R2 bucket in your Cloudflare dashboard
- Generate API tokens with read/write permissions
- Set the endpoint to your R2 bucket URL
S3_ENDPOINT="https://<account-id>.r2.cloudflarestorage.com"
S3_REGION="auto"AWS S3 Setup
For AWS S3, use the standard configuration:
S3_ENDPOINT="" # Leave empty for AWS
S3_REGION="us-east-1"Storage Instance
The storage instance is created in src/lib/storage/server.ts:
import { S3StorageProvider } from "./providers/s3";
import { env } from "@/env/env-server";
export const storage = new S3StorageProvider({
bucket: env.S3_BUCKET,
region: env.S3_REGION,
endpoint: env.S3_ENDPOINT,
credentials: {
accessKeyId: env.S3_ACCESS_KEY,
secretAccessKey: env.S3_SECRET_KEY,
},
});Custom Providers
You can implement custom storage providers by implementing the StorageProvider interface:
interface StorageProvider {
upload(path: string, file: Buffer, contentType: string): Promise<void>;
download(path: string): Promise<DownloadResult>;
getSignedUrl(path: string, action: "read" | "write"): Promise<string>;
delete(path: string): Promise<void>;
exists(path: string): Promise<boolean>;
}