pub struct FormFile { /* private fields */ }Expand description
One file part of a multipart/form-data request.
Cloning a FormFile is cheap: all clones share the same underlying bytes or
spooled temporary file, and the temporary file is removed when the last
clone is dropped.
Implementations§
Source§impl FormFile
impl FormFile
Sourcepub fn field_name(&self) -> &str
pub fn field_name(&self) -> &str
The form field name this file arrived under (e.g. "avatar").
Sourcepub fn file_name(&self) -> &str
pub fn file_name(&self) -> &str
A filesystem-safe basename derived from the client-supplied filename.
Path separators, control characters and Windows-reserved characters are
removed, so this is safe to pass to Path::join. Use
FormFile::original_file_name if you need the raw value for display.
Sourcepub fn original_file_name(&self) -> &str
pub fn original_file_name(&self) -> &str
The filename exactly as sent by the client, without sanitisation.
Never use this to build a filesystem path.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
The part’s declared content type, if the client sent one.
This is attacker-controlled metadata: treat it as a hint, not a guarantee.
Sourcepub fn extension(&self) -> Option<String>
pub fn extension(&self) -> Option<String>
Lowercase file extension of FormFile::file_name, without the dot.
Sourcepub fn path(&self) -> Option<&Path>
pub fn path(&self) -> Option<&Path>
The spooled temporary file path, when the upload was large enough to be written to disk.
The path is only valid while this FormFile (or a clone) is alive.
Prefer FormFile::save_as to hand a file to the rest of your
application.
Sourcepub async fn open(&self) -> Result<Box<dyn AsyncRead + Unpin + Send>, Error>
pub async fn open(&self) -> Result<Box<dyn AsyncRead + Unpin + Send>, Error>
Open the uploaded content as an async reader.
Memory-backed files read from a reference-counted buffer without copying it; spooled files are opened from disk. Either way the read is streamed.
Sourcepub async fn read_bytes(&self) -> Result<Vec<u8>, Error>
pub async fn read_bytes(&self) -> Result<Vec<u8>, Error>
Read the whole upload into memory.
Prefer FormFile::open or FormFile::copy_to for files that may be
large.