Skip to main content

FileStorage

Trait FileStorage 

Source
pub trait FileStorage:
    Send
    + Sync
    + 'static {
    // Required methods
    fn store<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
        file: &'life2 UploadedFile,
    ) -> Pin<Box<dyn Future<Output = Result<StoredFile, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn store_stream<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
        stream: &'life2 mut BufferedUpload,
    ) -> Pin<Box<dyn Future<Output = Result<StoredFile, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        path: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        path: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for persisting uploaded files to a storage backend.

Both in-memory (UploadedFile) and chunked (BufferedUpload) uploads are supported. Implementors must be Send + Sync + 'static so they can be shared across async tasks.

Required Methods§

Source

fn store<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prefix: &'life1 str, file: &'life2 UploadedFile, ) -> Pin<Box<dyn Future<Output = Result<StoredFile, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store a buffered in-memory file under prefix/.

A ULID-based unique filename is generated automatically. Returns the stored path and size on success.

Source

fn store_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prefix: &'life1 str, stream: &'life2 mut BufferedUpload, ) -> Pin<Box<dyn Future<Output = Result<StoredFile, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store a chunked upload under prefix/.

Chunks are consumed from stream sequentially. Returns the stored path and size on success.

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a file by its storage path (as returned by store).

Source

fn exists<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Return true if a file exists at the given storage path.

Implementors§