pub struct StoredFile { /* private fields */ }fs only.Expand description
One received file, in memory or in a temporary file.
Dropping it without persist deletes it (closing the
handle first) and wipes memory-held bytes. Debug never prints the file
name or the data.
§Examples
use std::io::Read;
let body = b"--X\r\nContent-Disposition: form-data; name=doc; filename=a.txt\r\n\r\nhello\r\n--X--";
let upload = form_net::read_multipart(b"multipart/form-data; boundary=X", &body[..])?;
let file = upload.file("doc").unwrap();
let mut text = String::new();
file.reader()?.read_to_string(&mut text).unwrap();
assert_eq!((text.as_str(), file.len(), file.is_in_memory()), ("hello", 5, true));Implementations§
Source§impl StoredFile
impl StoredFile
Sourcepub fn content_type(&self) -> Option<ContentType<'_>>
pub fn content_type(&self) -> Option<ContentType<'_>>
The declared content type: a hint, never trusted.
Sourcepub const fn is_in_memory(&self) -> bool
pub const fn is_in_memory(&self) -> bool
Whether the file is held in memory.
Sourcepub fn reader(&self) -> Result<StoredReader<'_>, FormError>
pub fn reader(&self) -> Result<StoredReader<'_>, FormError>
A reader over the file, in memory or on disk. It reads with positional reads, so several readers can exist at once.
§Errors
Io { kind } when the file is gone.
Sourcepub fn read_to_vec(&self, max: u64) -> Result<Vec<u8>, FormError>
pub fn read_to_vec(&self, max: u64) -> Result<Vec<u8>, FormError>
The whole file in a new vector, refusing a file longer than max
before allocating.
§Errors
Limit { FileSize }; Io { kind }.
Sourcepub fn persist(self, dest: &Path) -> Result<(), FormError>
pub fn persist(self, dest: &Path) -> Result<(), FormError>
Moves the finished upload to dest, which the caller built. It never
overwrites: a named file is hard-linked when dest is on the same file
system and copied otherwise; anonymous and memory files are copied
into dest opened with create_new. Whether to fsync dest and its
directory is the caller’s choice. On error the temporary file is
deleted like any dropped file.
§Errors
Store { DestinationExists }; Io { kind }.
Trait Implementations§
Source§impl Debug for StoredFile
impl Debug for StoredFile
Source§impl Drop for StoredFile
impl Drop for StoredFile
Source§impl FromField for StoredFile
impl FromField for StoredFile
Source§fn accept_file(
slot: &mut Self::Slot,
file: FileValue<'_>,
) -> Result<(), ValueError>
fn accept_file( slot: &mut Self::Slot, file: FileValue<'_>, ) -> Result<(), ValueError>
alloc only.Source§fn finish(slot: Self::Slot) -> Result<Self, ValueError>
fn finish(slot: Self::Slot) -> Result<Self, ValueError>
alloc only.Source§fn accept_text(slot: &mut Self::Slot, value: &str) -> Result<(), ValueError>
fn accept_text(slot: &mut Self::Slot, value: &str) -> Result<(), ValueError>
alloc only.