pub struct Multipart { /* private fields */ }
Available on crate feature
multipart
only.Expand description
Extractor that parses multipart/form-data
requests (commonly used with file uploads).
⚠️ Since extracting multipart form data from the request requires consuming the body, the
Multipart
extractor must be last if there are multiple extractors in a handler.
See “the order of extractors”
§Example
use axum::{
extract::Multipart,
routing::post,
Router,
};
use futures_util::stream::StreamExt;
async fn upload(mut multipart: Multipart) {
while let Some(mut field) = multipart.next_field().await.unwrap() {
let name = field.name().unwrap().to_string();
let data = field.bytes().await.unwrap();
println!("Length of `{}` is {} bytes", name, data.len());
}
}
let app = Router::new().route("/upload", post(upload));
§Large Files
For security reasons, by default, Multipart
limits the request body size to 2MB.
See DefaultBodyLimit
for how to configure this limit.
Implementations§
Source§impl Multipart
impl Multipart
Sourcepub async fn next_field(&mut self) -> Result<Option<Field<'_>>, MultipartError>
pub async fn next_field(&mut self) -> Result<Option<Field<'_>>, MultipartError>
Yields the next Field
if available.
Trait Implementations§
Source§impl<S> FromRequest<S> for Multipart
impl<S> FromRequest<S> for Multipart
Source§type Rejection = MultipartRejection
type Rejection = MultipartRejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Auto Trait Implementations§
impl Freeze for Multipart
impl !RefUnwindSafe for Multipart
impl Send for Multipart
impl Sync for Multipart
impl Unpin for Multipart
impl !UnwindSafe for Multipart
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