Skip to main content

StorageConfig

Struct StorageConfig 

Source
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: String

local (the default), s3, or none to refuse uploads outright.

§dir: String

local: 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: String

URL prefix the stored links carry and the server answers on. Always starts with / and never ends with one (normalised on load).

§max_size_mb: u64

Largest 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: String

s3: the bucket. Required when backend = "s3".

§region: String

s3: the region. R2 and most S3-compatibles want auto.

§endpoint: String

s3: 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: String

s3: 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: String

Key prefix inside the bucket or directory, so several apps can share one.

§base_url: String

Serve 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

Source

pub fn is_active(&self) -> bool

Whether uploads are accepted at all.

Source

pub fn normalized_public_base(&self) -> String

/files — leading slash, no trailing slash, whatever was written.

Source

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.

Source

pub fn max_size_bytes(&self) -> u64

Trait Implementations§

Source§

impl Clone for StorageConfig

Source§

fn clone(&self) -> StorageConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StorageConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StorageConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StorageConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more