pub struct Storage { /* private fields */ }Expand description
A file storage disk: state.storage, or a named one from
state.disk_named(name).
Implementations§
Source§impl Storage
impl Storage
Sourcepub async fn put_encrypted(&self, key: &str, bytes: Bytes) -> Result
pub async fn put_encrypted(&self, key: &str, bytes: Bytes) -> Result
Encrypts bytes with AES-256-GCM and writes them to key. Each file
gets its own random data key, sealed with a key derived from APP_KEY
and kept in the file’s header (RNXE, a version, the sealed key, the
nonce, the ciphertext). Read it back with get_decrypted; local
temporary URLs and Download::decrypted decrypt on the fly. A private
key (not under public/) is what you want: /storage serves files as
stored.
state.storage.put_encrypted("ids/passport.jpg", vec![1, 2, 3].into()).await?;
let plain = state.storage.get_decrypted("ids/passport.jpg").await?;
assert_eq!(plain.as_deref(), Some(&[1u8, 2, 3][..]));Sourcepub async fn get_decrypted(&self, key: &str) -> Result<Option<Bytes>>
pub async fn get_decrypted(&self, key: &str) -> Result<Option<Bytes>>
The decrypted content of a file written with put_encrypted, or
None if there is no such key. Fails for a file that isn’t encrypted,
was changed, or was sealed with another APP_KEY.
Sourcepub async fn rewrap_encrypted(
&self,
prefix: &str,
old_app_key: &str,
) -> Result<usize>
pub async fn rewrap_encrypted( &self, prefix: &str, old_app_key: &str, ) -> Result<usize>
Re-seals the encrypted files under prefix ("" for the whole disk)
with this disk’s APP_KEY, after the key was rotated: old_app_key is
the previous APP_KEY value. Only each file’s header changes. Files
that aren’t encrypted, or were already re-sealed, are skipped; the
count of files changed is returned.
Sourcepub async fn put(&self, key: &str, bytes: Bytes) -> Result
pub async fn put(&self, key: &str, bytes: Bytes) -> Result
Writes bytes to key, replacing any file there.
Sourcepub async fn get(&self, key: &str) -> Result<Option<Bytes>>
pub async fn get(&self, key: &str) -> Result<Option<Bytes>>
The file’s bytes, or None if there is no such key.
Sourcepub async fn delete(&self, key: &str) -> Result
pub async fn delete(&self, key: &str) -> Result
Deletes the file; deleting a missing key is not an error.
Sourcepub async fn list(&self, prefix: &str) -> Result<Vec<FileInfo>>
pub async fn list(&self, prefix: &str) -> Result<Vec<FileInfo>>
The URL of a public file (a key under public/).
The files under prefix (a folder like invoices/2026, or ""
for all), at any depth, sorted by key.
for file in state.storage.list("invoices/2026").await? {
println!("{} ({} bytes)", file.key, file.size);
}
state.storage.copy("public/logo.png", "public/logo-old.png").await?;
state.storage.rename("uploads/tmp/a.pdf", "invoices/2026/a.pdf").await?;
let removed = state.storage.delete_all("uploads/tmp").await?;Sourcepub async fn size(&self, key: &str) -> Result<Option<u64>>
pub async fn size(&self, key: &str) -> Result<Option<u64>>
The size of a file in bytes, if it exists.
Sourcepub async fn copy(&self, from: &str, to: &str) -> Result
pub async fn copy(&self, from: &str, to: &str) -> Result
Copies a file, replacing to if it exists. A missing from is a
404.
Sourcepub async fn rename(&self, from: &str, to: &str) -> Result
pub async fn rename(&self, from: &str, to: &str) -> Result
Moves a file (Laravel’s move), replacing to if it exists. A
missing from is a 404.
Sourcepub async fn delete_all(&self, prefix: &str) -> Result<usize>
pub async fn delete_all(&self, prefix: &str) -> Result<usize>
Deletes every file under prefix (not "": that would be all of
them); returns how many.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnsafeUnpin for Storage
impl UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more