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_qs (form-encoding mode) before Sanitize::sanitize is called on the
result. Repeated text fields, nested structs (address[city]=…), and indexed-bracket
Vec<Struct> rows (contacts[0][kind]=…) all deserialize naturally — same behavior
as crate::extractor::FormRequest. 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 its
IntoResponse impl.
§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: Files