Storage
AWS S3 / Cloudflare R2
Store uploads in an S3-compatible bucket (AWS S3 or Cloudflare R2).
| Cloud | Self-Hosted | Links |
|---|---|---|
| ✅ Supported | ✅ Supported | NPM Package |
A single adapter covers both AWS S3 and Cloudflare R2 — R2 is
S3-compatible, so you only add a custom endpoint.
Usage
Installation
bun i @vitnode/s3 -Dpnpm i @vitnode/s3 -Dnpm i @vitnode/s3 -DImport the adapter (AWS S3)
import { S3StorageAdapter } from "@vitnode/s3";
import { buildApiConfig } from "@vitnode/core/vitnode.config";
export const vitNodeApiConfig = buildApiConfig({
storage: {
adapter: S3StorageAdapter({
bucket: process.env.S3_BUCKET,
region: process.env.S3_REGION,
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
}),
},
});Environment variables
S3_BUCKET=your-bucket
S3_REGION=us-east-1
S3_ACCESS_KEY_ID=your_access_key_id
S3_SECRET_ACCESS_KEY=your_secret_access_keyCloudflare R2
R2 uses the same adapter — add your account endpoint and (optionally) the
public bucket URL:
adapter: S3StorageAdapter({
bucket: process.env.S3_BUCKET,
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
endpoint: process.env.S3_ENDPOINT, // https://<account>.r2.cloudflarestorage.com
publicUrl: process.env.S3_PUBLIC_URL, // https://cdn.example.com
}),Options
Prop
Type