pub struct FormFileBuilder { /* private fields */ }Expand description
Incrementally builds a FormFile while a multipart part streams in.
The builder buffers in memory up to memory_threshold bytes and spills to a
temporary file beyond that, so peak memory per upload is bounded regardless
of file size.
Implementations§
Source§impl FormFileBuilder
impl FormFileBuilder
Sourcepub fn new(
field_name: impl Into<String>,
raw_file_name: impl Into<String>,
content_type: Option<String>,
) -> FormFileBuilder
pub fn new( field_name: impl Into<String>, raw_file_name: impl Into<String>, content_type: Option<String>, ) -> FormFileBuilder
Start building a file for field_name.
raw_file_name is the client-supplied name; it is sanitised by
sanitize_file_name when the file is finished.
Sourcepub fn memory_threshold(self, bytes: usize) -> FormFileBuilder
pub fn memory_threshold(self, bytes: usize) -> FormFileBuilder
Bytes kept in memory before spilling to disk. Default: 1 MiB.
Sourcepub fn max_size(self, bytes: u64) -> FormFileBuilder
pub fn max_size(self, bytes: u64) -> FormFileBuilder
Maximum accepted size for this file. Default: 128 MiB.
Exceeding it fails the upload with Error::PayloadTooLarge.
Sourcepub fn spool_dir(self, dir: impl Into<PathBuf>) -> FormFileBuilder
pub fn spool_dir(self, dir: impl Into<PathBuf>) -> FormFileBuilder
Directory used for spooled files. Default: spool_root.
Sourcepub async fn write(&mut self, chunk: &[u8]) -> Result<(), Error>
pub async fn write(&mut self, chunk: &[u8]) -> Result<(), Error>
Append a chunk of the current part.
Returns Error::PayloadTooLarge as soon as the file exceeds
FormFileBuilder::max_size, so an oversized upload is rejected
without buffering the whole body.