# Multipart
File uploads use the multipart/form-data content type. Handling this involves streaming the request body and parsing the distinct parts (fields and files).
#actix-multipart
Actix Web doesn't include multipart parsing in the core framework; you must use the actix-multipart crate.
code_blockstoml
[dependencies]
actix-web = "4"
actix-multipart = "0.6"
futures-util = "0.3"#Processing a Stream
Multipart data is asynchronous and stream-based. You iterate over a Multipart stream, getting Field objects.
code_blocksrust
use actix_multipart::Multipart;
use actix_web::{post, HttpResponse, Error};
use futures_util::stream::StreamExt as _;
#[post("/upload")]
async fn upload(mut payload: Multipart) -> Result<HttpResponse, Error> {
while let Some(item) = payload.next().await {
let mut field = item?;
println!("Field Name: {}", field.name());
// Read chunks
while let Some(chunk) = field.next().await {
let data = chunk?;
// Save data to file...
}
}
Ok(HttpResponse::Ok().into())
}