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 re-encoded as application/x-www-form-urlencoded and deserialized
via serde_urlencoded before Sanitize::sanitize is called on the result. File
fields are fully buffered into memory as UploadedFile values.
§Errors
The FromRequest::Rejection is crate::Error. A 400 Bad Request is returned
if the request is not a valid multipart/form-data body, a field cannot be read,
or the collected text fields cannot be deserialized into T. The error renders via
[crate::Error::into_response].
§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