pub trait FileStorage: Sync + 'static {
// Required methods
async fn store(
&self,
prefix: &str,
file: &UploadedFile,
) -> Result<StoredFile, Error>;
async fn store_stream(
&self,
prefix: &str,
stream: &mut BufferedUpload,
) -> Result<StoredFile, Error>;
async fn delete(&self, path: &str) -> Result<(), Error>;
async fn exists(&self, path: &str) -> Result<bool, Error>;
}Expand description
Trait for persisting uploaded files to a storage backend.
Both in-memory (UploadedFile) and chunked (BufferedUpload) uploads
are supported. Implementors must be Sync + 'static so they can be
shared across async tasks behind an Arc<dyn FileStorageDyn>.
Use the storage() factory function to construct the
backend configured by UploadConfig, or instantiate
a concrete backend directly (e.g. LocalStorage).
Use FileStorageDyn (object-safe companion) for trait objects:
Arc<dyn FileStorageDyn>. Any type implementing FileStorage
automatically implements FileStorageDyn via a blanket impl.
Required Methods§
Sourceasync fn store(
&self,
prefix: &str,
file: &UploadedFile,
) -> Result<StoredFile, Error>
async fn store( &self, prefix: &str, file: &UploadedFile, ) -> Result<StoredFile, Error>
Store a buffered in-memory file under prefix/.
A ULID-based unique filename is generated automatically. Returns the stored path and size on success.
Sourceasync fn store_stream(
&self,
prefix: &str,
stream: &mut BufferedUpload,
) -> Result<StoredFile, Error>
async fn store_stream( &self, prefix: &str, stream: &mut BufferedUpload, ) -> Result<StoredFile, Error>
Store a chunked upload under prefix/.
Chunks are consumed from stream sequentially.
Returns the stored path and size on success.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.