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::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, ViaRequest> for Multipartwhere
B: HttpBody + Send + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
S: Send + Sync,
impl<S, B> FromRequest<S, B, ViaRequest> for Multipartwhere B: HttpBody + Send + 'static, B::Data: Into<Bytes>, B::Error: Into<BoxError>, S: Send + Sync,
§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.