Cloudflare R2 & S3
With VELA_STORAGE=r2, file contents live in a private Cloudflare R2 bucket — or any S3-compatible service — while SQLite metadata stays on the server. The API, the CLI, URLs and access rules do not change; only where the bytes rest and how they travel.
When to use it
- Your server's disk is small, but you need to store a lot.
- You want contents in object storage with its own durability and replication.
- You want downloads to bypass your server's bandwidth (redirect mode).
The trade-offs: uploads and (in proxy mode) downloads pass through velad, multipart uploads need memory, and backups become a two-part job. Both backends behave identically through the API, and you can migrate in either direction.
What goes where
| Data | Location |
|---|---|
| Paths, metadata, keys, links, trash, policies | /data/vela.db on the server |
| File contents | <bucket>/<VELA_R2_PREFIX><shard>/<blob-id>, e.g. blobs/r7/c4/01m4tscd50ry5wfktp4mx4r7c4 |
| Temporary upload files | none — uploads stream directly as multipart |
Object keys contain only random blob IDs, never file names or paths, and renames never touch the bucket. SQLite is always the source of truth.
Set up the bucket
-
Create a private bucket
In the Cloudflare dashboard create a bucket, for example
vela-store, with a location hint near your server. Keep public access off, leave ther2.devsubdomain disabled and do not attach a custom domain. Everything must go through Vela. -
Add a lifecycle rule
Add Abort incomplete multipart uploads after 1 day. The janitor already aborts Vela's own stale uploads; the rule covers crashes in between.
-
Create a bucket-scoped token
Under R2 → Manage API tokens → Create, grant Object Read & Write restricted to this bucket only, with no account permissions. Note the access key ID, secret access key and your account ID.
-
Configure Vela
Start from
examples/env/r2.env.example:VELA_PUBLIC_URL=https://store.example.com VELA_STORAGE=r2 VELA_ACCEL_PREFIX= VELA_R2_ACCOUNT_ID=0123456789abcdef0123456789abcdef VELA_R2_BUCKET=vela-store VELA_R2_ACCESS_KEY_ID=CHANGE-ME VELA_R2_SECRET_ACCESS_KEY=CHANGE-ME VELA_R2_PREFIX=blobs/ VELA_R2_DELIVERY=proxy -
Start and check
VELA_IMAGE=xchunk/vela:0.9.0 ./examples/docker/run-r2.sh docker logs vela | grep 'velad started' # delivery=r2 proxy vela put test.bin check/test.bin --private # proves write access vela get check/test.bin - | sha256sumStartup runs a
HeadBucketcheck, but that cannot prove write permission — only a real upload does.
Credentials are explicitThe backend reads only the VELA_R2_* variables. It ignores AWS_* environment variables, ~/.aws files and instance metadata, and credentials are never accepted as command-line flags. Keep the env file mode 0600 and out of version control.
Configuration
| Variable | Default | Meaning |
|---|---|---|
VELA_STORAGE | fs | r2 selects this backend (also for generic S3) |
VELA_R2_ACCOUNT_ID | empty | Cloudflare account; required unless VELA_R2_ENDPOINT is set |
VELA_R2_ENDPOINT | https://<account>.r2.cloudflarestorage.com | Bare http(s) origin of the S3 API |
VELA_R2_REGION | auto | Signing region; set your provider's region for other services |
VELA_R2_BUCKET | required | Existing private bucket |
VELA_R2_PREFIX | blobs/ | Relative managed prefix, must end in /. Dedicate it to one Vela store. |
VELA_R2_ACCESS_KEY_ID | required | Bucket-scoped access key |
VELA_R2_SECRET_ACCESS_KEY | required | Bucket-scoped secret |
VELA_R2_DELIVERY | proxy | proxy or redirect |
VELA_R2_PRESIGN_TTL | 5m | Redirect grant lifetime, 1 s – 1 h (Go duration syntax, e.g. 90s, 10m) |
VELA_R2_PART_SIZE | 8MiB | Multipart part size, 5–64 MiB |
VELA_R2_UPLOAD_CONCURRENCY | 2 | Parts uploaded in parallel per upload, 1–16 |
VELA_R2_PATH_STYLE | true | Path-style addressing; false for virtual-hosted buckets |
VELA_MAX_CONCURRENT_UPLOADS | 4 | Active uploads (1–1024); extra uploads wait, cancellable by the client |
R2 mode requires an empty VELA_ACCEL_PREFIX; a non-empty one fails at startup.
Delivery: proxy or redirect
proxy (default) | redirect | |
|---|---|---|
| How | Go fetches from the bucket and streams to the client | Go answers 302 to a short-lived presigned GET |
| Bandwidth | Through your server | Directly from the bucket |
| Client sees | Only your hostname | The S3 hostname after the redirect |
| Ranges | Single ranges (206); multi-range falls back to a full 200 | Handled by the bucket |
| Revocation | Immediate | An issued grant stays valid until its short TTL ends |
| Requirement | Proxy buffering/temp files disabled | Clients can reach the S3 origin |
Proxy mode details
HEAD requests and matching conditional requests are answered from SQLite without touching the bucket. Size and content type come from the database, the ETag is "sha256:<hex>", and all policy headers are set by Go. If the client disconnects, the bucket read is cancelled. Keep proxy_buffering off and proxy_max_temp_file_size 0 in nginx so downloads never spool to the server disk.
Redirect mode details
- Go checks access exactly as usual, then redirects. The presigned URL carries the response content type, disposition (with
filename*) and cache policy, so browsers receive the right headers from the bucket. - The
302itself isCache-Control: private, no-storeandReferrer-Policy: no-referrer; crawler hints (X-Robots-Tag) are emitted on the redirect. - Grants are capped at the object's or link's own expiry, so a redirect never extends access.
- Near expiry, and for any request with conditional headers (
If-Match,If-None-Match,If-Range, timestamp conditions), Vela falls back to proxy delivery so its SHA-256 validators apply. - The Go client and the CLI strip
AuthorizationandRefererwhen following redirects, so keys never reach the bucket.
An S3 grant that was already issued remains valid until its TTL — at most VELA_R2_PRESIGN_TTL — even if you revoke the link or make the file private in the meantime. Keep the TTL short.
Other S3-compatible services
The same backend works with other S3 APIs. Set an explicit endpoint and the provider's signing region; the account ID can stay empty:
VELA_STORAGE=r2
VELA_R2_ENDPOINT=https://s3.eu-central-1.example-provider.com
VELA_R2_REGION=eu-central-1
VELA_R2_BUCKET=vela-store
VELA_R2_PATH_STYLE=false # if the provider requires virtual-hosted addressing
VELA_R2_ACCESS_KEY_ID=CHANGE-ME
VELA_R2_SECRET_ACCESS_KEY=CHANGE-ME
MinIO is exercised by the test suite. Other providers need their own verification: test small and multipart uploads, downloaded SHA-256, presigned URLs (for redirect mode), interrupted uploads and janitor cleanup on an isolated bucket or prefix before production.
Memory planning
Uploads stream as multipart without staging whole files, but the pinned AWS SDK buffers parts in memory. The payload buffers are approximately:
part size × (part concurrency + 2) × active uploads
= 8 MiB × (2 + 2) × 4 = 128 MiB at the defaults
Growth of the first part creates extra transient allocations, so reserve at least:
part size × (part concurrency + 4) × active uploads
= 8 MiB × (2 + 4) × 4 = 192 MiB at the defaults
plus headroom for garbage collection, TLS, SQLite and request buffers. This is a capacity-planning allowance, not a hard RSS bound. On a small VPS, lower VELA_MAX_CONCURRENT_UPLOADS first; extra uploads simply wait.
Upload size limits
S3 multipart uploads are capped at 10,000 parts and Vela uses a fixed part size, so the largest possible object is VELA_R2_PART_SIZE × 10000. Startup rejects a VELA_MAX_UPLOAD or VELA_MAX_CREATE above that ceiling.
| Part size | Maximum object | Reserve at defaults (2 parts, 4 uploads) |
|---|---|---|
5MiB | 48.8 GiB | 120 MiB |
8MiB (default) | 78.125 GiB | 192 MiB |
11MiB | 107.4 GiB | 264 MiB |
16MiB | 156.25 GiB | 384 MiB |
64MiB | 625 GiB | 1.5 GiB |
A 100 GiB limit therefore needs at least 11 MiB parts and a larger memory allowance. Migration from the filesystem preflights every referenced size against the ceiling before copying anything.
Timeouts, retries and health
- Requests have connection and header deadlines and at most three SDK attempts. There is no total deadline on streaming bodies, so large transfers are not cut off.
- A failed multipart write is aborted; a completed object with a wrong checksum is deleted.
- Backend errors are logged without raw SDK messages or presigned URLs.
/healthzincludes a bucketHeadBucketcheck, cached for 45 seconds so health probes do not hammer the API.
Backups and migration
In R2 mode velad backup writes only the SQLite snapshot. A consistent disaster-recovery copy needs the database and a matching copy of the bucket prefix, taken while Vela is stopped. See R2 backups for a complete procedure, and Storage Migration to move between the filesystem and R2.