pub struct StorageConfig {Show 13 fields
pub backend: String,
pub dir: String,
pub public_base: String,
pub max_size_mb: u64,
pub allowed_types: Vec<String>,
pub bucket: String,
pub region: String,
pub endpoint: String,
pub access_key_id: String,
pub secret_access_key: String,
pub path_style: Option<bool>,
pub prefix: String,
pub base_url: String,
}Expand description
Where uploaded files go.
A file field holds a relative URL — /files/2026/…/logo.png — never a
bucket address, and the server answers that URL from whichever backend is
configured. That is the whole point of the indirection: an app that starts
on a mounted volume and later moves to S3 changes four lines of TOML and
nothing else. No row is rewritten, because no row ever named the backend.
# A directory — a Docker volume, in practice.
[storage]
backend = "local"
dir = "storage"
# Or block storage. `r2` is `s3` with an endpoint, and so is MinIO.
[storage]
backend = "s3"
bucket = "app-uploads"
region = "auto"
endpoint = "https://${R2_ACCOUNT}.r2.cloudflarestorage.com"
access_key_id = "${R2_ACCESS_KEY_ID}"
secret_access_key = "${R2_SECRET_ACCESS_KEY}"Fields§
§backend: Stringlocal (the default), s3, or none to refuse uploads outright.
dir: Stringlocal: the directory uploads are written to, relative to the app root
unless absolute. In a container this is what you mount a volume at.
public_base: StringURL prefix the stored links carry and the server answers on. Always
starts with / and never ends with one (normalised on load).
max_size_mb: u64Largest upload accepted, in megabytes.
allowed_types: Vec<String>Content types an upload may declare, as exact types (image/png) or
wildcards (image/*). Empty (the default) accepts anything — an
authenticated caller is already trusted to write a row.
bucket: Strings3: the bucket. Required when backend = "s3".
region: Strings3: the region. R2 and most S3-compatibles want auto.
endpoint: Strings3: the API origin. Empty uses AWS’s own
(https://<bucket>.s3.<region>.amazonaws.com); set it for R2, MinIO,
Backblaze or any other S3-compatible service.
access_key_id: Strings3: credentials.
secret_access_key: String§path_style: Option<bool>s3: address objects as <endpoint>/<bucket>/<key> rather than putting
the bucket in the hostname. Required by MinIO and by R2 (the default
when an endpoint is set).
prefix: StringKey prefix inside the bucket or directory, so several apps can share one.
base_url: StringServe files from somewhere else entirely — a CDN, or a public bucket — by storing absolute URLs under this origin instead of relative ones.
Empty (the default) keeps links relative and proxies reads through the server, which is what makes a private bucket work. Setting it is a deliberate trade: faster, but the objects must be publicly readable and the links stop being portable.
Implementations§
Source§impl StorageConfig
impl StorageConfig
Sourcepub fn normalized_public_base(&self) -> String
pub fn normalized_public_base(&self) -> String
/files — leading slash, no trailing slash, whatever was written.
Sourcepub fn uses_path_style(&self) -> bool
pub fn uses_path_style(&self) -> bool
Whether objects are addressed as <endpoint>/<bucket>/<key>. Explicit
when written down; otherwise path-style exactly when a custom endpoint
is set, since that is what every S3-compatible service but AWS wants.
pub fn max_size_bytes(&self) -> u64
Trait Implementations§
Source§impl Clone for StorageConfig
impl Clone for StorageConfig
Source§fn clone(&self) -> StorageConfig
fn clone(&self) -> StorageConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more