pub struct Multipart { /* private fields */ }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));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, B> FromRequest<S, B> for Multipart
impl<S, B> FromRequest<S, B> 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