pub struct MultipartForm<T: MultipartCollect>(pub T);Expand description
Typed multipart/form-data extractor.
To extract typed data from a multipart stream, the inner type T must implement the
MultipartCollect trait. You should use the MultipartForm macro to derive this
for your struct.
Note that this extractor rejects requests with any other Content-Type such as multipart/mixed,
multipart/related, or non-multipart media types.
Add a MultipartFormConfig to your app data to configure extraction.
§Basic Use
Each field type should implement the FieldReader trait:
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
#[derive(MultipartForm)]
struct ImageUpload {
description: Text<String>,
timestamp: Text<i64>,
image: TempFile,
}§Optional and List Fields
You can also use Vec<T> and Option<T> provided that T: FieldReader.
A Vec field corresponds to an upload with multiple parts under the same field
name.
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
#[derive(MultipartForm)]
struct Form {
category: Option<Text<String>>,
files: Vec<TempFile>,
}§Field Renaming
You can use the #[multipart(rename = "foo")] attribute to receive a field by a different name.
use actix_multipart::form::{tempfile::TempFile, MultipartForm};
#[derive(MultipartForm)]
struct Form {
#[multipart(rename = "files[]")]
files: Vec<TempFile>,
}§Field Limits
You can use the #[multipart(limit = "<size>")] attribute to set field level limits. The limit
string is parsed using bytesize.
Note: the form is also subject to the global limits configured using MultipartFormConfig.
use actix_multipart::form::{tempfile::TempFile, text::Text, MultipartForm};
#[derive(MultipartForm)]
struct Form {
#[multipart(limit = "2 KiB")]
description: Text<String>,
#[multipart(limit = "512 MiB")]
files: Vec<TempFile>,
}§Unknown Fields
By default fields with an unknown name are ignored. They can be rejected using the
#[multipart(deny_unknown_fields)] attribute:
use actix_multipart::form::MultipartForm;
#[derive(MultipartForm)]
#[multipart(deny_unknown_fields)]
struct Form {}§Duplicate Fields
The behaviour for when multiple fields with the same name are received can be changed using the
#[multipart(duplicate_field = "<behavior>")] attribute:
- “ignore”: (default) Extra fields are ignored. I.e., the first one is persisted.
- “deny”: A
MultipartError::DuplicateFielderror response is returned. - “replace”: Each field is processed, but only the last one is persisted.
Note that Vec fields will ignore this option.
use actix_multipart::form::MultipartForm;
#[derive(MultipartForm)]
#[multipart(duplicate_field = "deny")]
struct Form {}Tuple Fields§
§0: TImplementations§
Source§impl<T: MultipartCollect> MultipartForm<T>
impl<T: MultipartCollect> MultipartForm<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap into inner T value.
Trait Implementations§
Source§impl<T: MultipartCollect> Deref for MultipartForm<T>
impl<T: MultipartCollect> Deref for MultipartForm<T>
Source§impl<T: MultipartCollect> DerefMut for MultipartForm<T>
impl<T: MultipartCollect> DerefMut for MultipartForm<T>
Source§impl<T> FromRequest for MultipartForm<T>where
T: MultipartCollect + 'static,
impl<T> FromRequest for MultipartForm<T>where
T: MultipartCollect + 'static,
Source§type Future = Pin<Box<dyn Future<Output = Result<MultipartForm<T>, <MultipartForm<T> as FromRequest>::Error>>>>
type Future = Pin<Box<dyn Future<Output = Result<MultipartForm<T>, <MultipartForm<T> as FromRequest>::Error>>>>
Self. Read moreSource§fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Self from request parts asynchronously.Auto Trait Implementations§
impl<T> Freeze for MultipartForm<T>where
T: Freeze,
impl<T> RefUnwindSafe for MultipartForm<T>where
T: RefUnwindSafe,
impl<T> Send for MultipartForm<T>where
T: Send,
impl<T> Sync for MultipartForm<T>where
T: Sync,
impl<T> Unpin for MultipartForm<T>where
T: Unpin,
impl<T> UnsafeUnpin for MultipartForm<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MultipartForm<T>where
T: UnwindSafe,
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<R> CryptoRng for R
impl<T> Formattable for T
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>
impl<R> RngCore for Rwhere
R: Rng,
Source§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read more