Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

S3-compatible file storage.

Cheaply cloneable (wraps Arc). Use Storage::new() to create a production instance from a BucketConfig. Storage::memory() is available inside #[cfg(test)] blocks and when the test-helpers feature is enabled.

Implementations§

Source§

impl Storage

Source

pub fn with_client(config: &BucketConfig, client: Client) -> Result<Self>

Create from a bucket configuration using a shared reqwest::Client.

The shared client is used for S3 operations (PUT, DELETE, HEAD, LIST). URL fetching (Storage::put_from_url) uses a separate internal client with redirects disabled.

§Errors

Returns an error if required BucketConfig fields are missing (e.g. empty bucket or endpoint) or if max_file_size is invalid.

Source

pub fn new(config: &BucketConfig) -> Result<Self>

Create from a bucket configuration (builds its own default reqwest::Client).

For shared connection pooling, prefer Storage::with_client.

§Errors

Returns an error if required BucketConfig fields are missing (e.g. empty bucket or endpoint) or if max_file_size is invalid.

Source

pub async fn put(&self, input: &PutInput) -> Result<String>

Upload bytes. Returns the generated S3 key.

§Errors

Returns Error::payload_too_large if the data exceeds the configured max_file_size, Error::bad_request if the prefix is invalid (empty, absolute, or contains path traversal), or Error::internal if the S3 PUT request fails.

Source

pub async fn put_with( &self, input: &PutInput, opts: PutOptions, ) -> Result<String>

Upload bytes with custom options. Returns the generated S3 key.

§Errors

Same error conditions as Storage::put().

Source

pub async fn delete(&self, key: &str) -> Result<()>

Delete a single key. No-op if missing.

§Errors

Returns an error if the key path is invalid or the S3 DELETE request fails.

Source

pub async fn delete_prefix(&self, prefix: &str) -> Result<()>

Delete all keys under a prefix. Issues O(n) network calls (one per key).

§Errors

Returns an error if the prefix path is invalid, the LIST request fails, or any individual DELETE request fails.

Source

pub fn url(&self, key: &str) -> Result<String>

Public URL (string concatenation, no network call).

Requires public_url to be set in BucketConfig. Returns an error if public_url is not configured.

§Errors

Returns an error if the key path is invalid or public_url is not set in the BucketConfig.

Source

pub async fn presigned_url( &self, key: &str, expires_in: Duration, ) -> Result<String>

Presigned GET URL with expiry.

§Errors

Returns an error if the key path is invalid or presigned URL generation fails.

Source

pub async fn exists(&self, key: &str) -> Result<bool>

Check if a key exists.

§Errors

Returns an error if the key path is invalid or the S3 HEAD request fails.

Source

pub async fn put_from_url(&self, input: &PutFromUrlInput) -> Result<String>

Fetch a file from a URL and upload it. Returns the generated S3 key.

Redirects are not followed. A hard-coded 30-second timeout applies. Returns an error when called on the memory backend.

§Errors

Returns an error if the URL is invalid (not http/https), the fetch times out, the response is non-2xx, the downloaded file exceeds max_file_size, or the subsequent S3 upload fails. Always errors on the in-memory backend.

Source

pub async fn put_from_url_with( &self, input: &PutFromUrlInput, opts: PutOptions, ) -> Result<String>

Fetch a file from a URL and upload it with custom options. Returns the generated S3 key.

Redirects are not followed. A hard-coded 30-second timeout applies. Returns an error when called on the memory backend.

§Errors

Same error conditions as Storage::put_from_url().

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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