Storage

Buckets and files, on disk or S3, signed URLs, and policies on storage.objects.

/storage/v1 keeps files in buckets, the way Supabase Storage does:

TypeScript
await supabase.storage.from("avatars").upload(`${user.id}/me.png`, file, { upsert: true });
const { data } = supabase.storage.from("avatars").getPublicUrl(`${user.id}/me.png`);

Each file is a row in storage.objects. Its bytes live in a backend:

TOML
[storage]
backend = "local"            # a folder: storage.path, default <data>/storage
file_size_limit = 52428800   # bytes; a bucket may set less

# or S3, and anything that speaks it (MinIO, Cloudflare R2, ...)
backend = "s3"
s3_bucket = "myapp-files"
s3_region = "eu-west-1"                     # default: AWS_REGION, then us-east-1
s3_endpoint = "https://<account>.r2.cloudflarestorage.com"   # S3-compatible services only
# keys: FORKBASE_S3_ACCESS_KEY_ID / FORKBASE_S3_SECRET_ACCESS_KEY, else AWS_* or the machine's role

Who may do what

Row-level security on storage.objects (and storage.buckets) decides. Every request reads and writes those rows as the caller. With no policy, only the service key reaches them.

Policies can use auth.uid(), the row's owner (who uploaded it), and the helpers storage.foldername(name), storage.filename(name) and storage.extension(name):

SQL
-- each person reads and writes only their own folder in "docs"
create policy own_folder on storage.objects for all to authenticated
  using (bucket_id = 'docs' and (storage.foldername(name))[1] = auth.uid())
  with check (bucket_id = 'docs' and (storage.foldername(name))[1] = auth.uid());

Buckets

Route
GET /bucket, POST /bucketlist; make one: {id, name?, public?, file_size_limit?, allowed_mime_types?}
GET, PUT, DELETE /bucket/{id}read, change, delete (an empty bucket)
POST /bucket/{id}/emptydelete every file in it
  • public: true: anyone reads its files at /object/public/{bucket}/{path}, no key.
  • file_size_limit: bytes, or "5MB".
  • allowed_mime_types: ["image/*", "application/pdf"].

Files

Route
POST /object/{bucket}/{path}upload: a raw body with its content-type, or a form as supabase-js sends a Blob. x-upsert: true replaces a file already there
PUT /object/{bucket}/{path}replace only
GET /object/{bucket}/{path}download (?download to save it); etag and If-None-Match
GET /object/public/{bucket}/{path}download from a public bucket, no key
GET /object/info/{bucket}/{path}its size, type, owner, times
POST /object/list/{bucket}{prefix, search, limit, offset, sortBy}; folders come back with id: null
POST /object/move, POST /object/copy{bucketId, sourceKey, destinationKey, destinationBucket?}
DELETE /object/{bucket}/{path}delete one
DELETE /object/{bucket}{"prefixes": ["a.png", "b/c.png"]}: delete several

Signed URLs

  • POST /object/sign/{bucket}/{path} {"expiresIn": 60} (or POST /object/sign/{bucket} with paths), by someone who may read the file: a URL anyone can read it at until then.
  • POST /object/upload/sign/{bucket}/{path}, by someone who may upload there: a URL anyone can PUT that one file to for two hours. The file belongs to whoever made the URL.

Guarantees and limits

  • Every upload is a new version of the bytes, so a reader never gets half of one. Replaced or deleted bytes are removed once no row points at them.
  • Not yet: image transforms, resumable (TUS) uploads, byte ranges.

Something wrong or missing? Edit this page on GitHub or open an issue.

Storage · Forkbase