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
impl Storage
Sourcepub fn with_client(config: &BucketConfig, client: Client) -> Result<Self>
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.
Sourcepub fn new(config: &BucketConfig) -> Result<Self>
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.
Sourcepub async fn put(&self, input: &PutInput) -> Result<String>
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.
Sourcepub async fn put_with(
&self,
input: &PutInput,
opts: PutOptions,
) -> Result<String>
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().
Sourcepub async fn delete(&self, key: &str) -> Result<()>
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.
Sourcepub async fn delete_prefix(&self, prefix: &str) -> Result<()>
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.
Sourcepub fn url(&self, key: &str) -> Result<String>
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.
Sourcepub async fn presigned_url(
&self,
key: &str,
expires_in: Duration,
) -> Result<String>
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.
Sourcepub async fn exists(&self, key: &str) -> Result<bool>
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.
Sourcepub async fn put_from_url(&self, input: &PutFromUrlInput) -> Result<String>
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.
Sourcepub async fn put_from_url_with(
&self,
input: &PutFromUrlInput,
opts: PutOptions,
) -> Result<String>
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().