pub struct MultipartRequest<T>(pub T, pub Files);Expand description
Axum extractor for multipart/form-data requests.
Splits the multipart body into text fields (deserialized and sanitized into T) and
file fields (collected into a Files map). The inner tuple is (T, Files).
Text fields are URL-encoded and deserialized via serde_urlencoded before
Sanitize::sanitize is called on the result. File fields are collected into memory
as UploadedFile values.
Returns a 400 Bad Request error if the request is not valid multipart data or a field cannot be read.
§Example
use modo::extractor::{MultipartRequest, Files};
use modo::sanitize::Sanitize;
use serde::Deserialize;
#[derive(Deserialize)]
struct ProfileForm {
display_name: String,
}
impl Sanitize for ProfileForm {
fn sanitize(&mut self) {
self.display_name = self.display_name.trim().to_string();
}
}
async fn update_profile(
MultipartRequest(form, mut files): MultipartRequest<ProfileForm>,
) {
let avatar = files.file("avatar"); // Option<UploadedFile>
}Tuple Fields§
§0: T§1: FilesTrait Implementations§
Source§impl<S, T> FromRequest<S> for MultipartRequest<T>
impl<S, T> FromRequest<S> for MultipartRequest<T>
Auto Trait Implementations§
impl<T> Freeze for MultipartRequest<T>where
T: Freeze,
impl<T> RefUnwindSafe for MultipartRequest<T>where
T: RefUnwindSafe,
impl<T> Send for MultipartRequest<T>where
T: Send,
impl<T> Sync for MultipartRequest<T>where
T: Sync,
impl<T> Unpin for MultipartRequest<T>where
T: Unpin,
impl<T> UnsafeUnpin for MultipartRequest<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MultipartRequest<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
Mutably borrows from an owned value. Read more