Expand description
multipart/form-data parsing for file uploads and mixed forms.
The request body is already buffered in the RequestContext (the one
pipeline reads it once, subject to the LaunchConfig body cap), so this
parses that buffer rather than touching the socket again. Call it from a
handler that received the raw context:
ⓘ
#[Post("/avatar")]
async fn upload(&self, ctx: &RequestContext) -> Result<String, Error> {
let form = MultipartForm::from_ctx(ctx).await?;
let file = form.file("avatar").ok_or(Error::BadRequest("avatar required"))?;
store(file.file_name.as_deref(), &file.bytes).await;
Ok(format!("received {} bytes", file.bytes.len()))
}Structs§
- Multipart
Form - A fully parsed
multipart/form-databody. - Part
- One part of a parsed multipart body — a form field or an uploaded file.