Hosting · Blob storage

Blob storage

Blobs are the files that apps upload. You choose where they are stored in /admin/storage. This page covers the choices, the settings, and how to move blobs to a different place.

Providers

Provider Where files go Use it when
Local filesystem A directory on the server You run one server with a disk you already back up.
S3-compatible A bucket (AWS S3, Cloudflare R2, Tigris, Hetzner, MinIO and others) You want files off the server's disk, or served from a CDN.
Disabled Nowhere. Uploads are refused. The server should store no files.

Before you save a provider

Until you save a provider in /admin/storage, blobs go to the directory in the CIVILITY_BLOB_PATH environment variable. The default is ./.data/blobs, relative to where the server starts.

In a container, point CIVILITY_BLOB_PATH at a mounted volume. The Docker template's entrypoint does this ($DATA_DIR/blobs).

A saved provider always wins over CIVILITY_BLOB_PATH.

Set a provider

  1. Open /admin/storage.
  2. Choose a provider and fill in its fields.
  3. Save.

The change applies to the next request, with no restart. Saving a provider does not move files that are already stored. See Move to a different place.

Local filesystem

Field Notes
Directory The path on the server where files are written. Required. Put it on a disk you back up. Losing it loses every uploaded file.

S3-compatible

Field Notes
Endpoint Required. Host name only, with no https://, port or path. Example: s3.example.com.
Port Optional. Leave empty for 443 (or 80 with plain HTTP). A MinIO often listens on 9000.
Use plain HTTP (no TLS) Off by default. Only for a bucket on a private network you trust: keys and files travel unencrypted.
Bucket Required.
Access key Required.
Secret key Required the first time. Leave blank later to keep the stored key.
Region Optional.
CDN URL base Optional. The public URL your bucket is served from, for example https://blobs.example.com.

The secret key is encrypted with CIVILITY_AUTH_SECRET and never shown again.

Disabled

Uploads fail with blob.storage_unconfigured (HTTP 503). Reads return nothing.

The server also tells apps that it stores no files, so they do not try. Notes, settings and other data still sync between a person's devices. Photos and other files stay on the device that added them, and other devices show a placeholder. If you configure storage later, each device uploads the files it was holding the next time it connects.

How files are served

  • Signed-in downloads always go through the server. Range requests work, so audio and video can seek.
  • With an S3 bucket and a CDN URL base, upload responses carry the CDN URL and public share links redirect to it.

Move to a different place

The database refers to each blob by its hash, not by where it is stored. To change provider or bucket without losing files:

  1. Copy every file from the old place to the new one. A plain copy only works between two places of the same kind (directory to directory, bucket to bucket). The local filesystem stores each file as <aa>/<bb>/<hex> with a <hex>.meta file beside it; a bucket stores it as one object named sha256:<hex> at the bucket root. To go from a directory to a bucket, upload each <aa>/<bb>/<hex> as sha256:<hex>, with its Content-Type taken from mime in <hex>.meta, and do not upload the .meta files.

  2. Save the new provider in /admin/storage.

  3. Open an app and check that a file uploaded before the move still loads.

  4. Optionally run a cleanup sweep. It only marks files that nothing refers to; they are deleted by a later sweep, after the grace period:

    civ api gc blobs --once --db-path /path/to/civility.db
    

    If the new provider is an S3 bucket, set CIVILITY_AUTH_SECRET in the command's environment so it can read the stored key.

  5. Delete the old copy.

See Maintenance for the command's options.

See also