actix_multipart/
lib.rs

1//! Multipart form support for Actix Web.
2//!
3//! # Examples
4//!
5//! ```no_run
6//! use actix_web::{post, App, HttpServer, Responder};
7//!
8//! use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm};
9//! use serde::Deserialize;
10//!
11//! #[derive(Debug, Deserialize)]
12//! struct Metadata {
13//!     name: String,
14//! }
15//!
16//! #[derive(Debug, MultipartForm)]
17//! struct UploadForm {
18//!     #[multipart(limit = "100MB")]
19//!     file: TempFile,
20//!     json: MpJson<Metadata>,
21//! }
22//!
23//! #[post("/videos")]
24//! pub async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Responder {
25//!     format!(
26//!         "Uploaded file {}, with size: {}",
27//!         form.json.name, form.file.size
28//!     )
29//! }
30//!
31//! #[actix_web::main]
32//! async fn main() -> std::io::Result<()> {
33//!     HttpServer::new(move || App::new().service(post_video))
34//!         .bind(("127.0.0.1", 8080))?
35//!         .run()
36//!         .await
37//! }
38//! ```
39//!
40//! cURL request:
41//!
42//! ```sh
43//! curl -v --request POST \
44//!   --url http://localhost:8080/videos \
45//!   -F 'json={"name": "Cargo.lock"};type=application/json' \
46//!   -F file=@./Cargo.lock
47//! ```
48
49#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
50#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
51#![cfg_attr(docsrs, feature(doc_auto_cfg))]
52
53// This allows us to use the actix_multipart_derive within this crate's tests
54#[cfg(test)]
55extern crate self as actix_multipart;
56
57mod error;
58mod extractor;
59pub(crate) mod field;
60pub mod form;
61mod multipart;
62pub(crate) mod payload;
63pub(crate) mod safety;
64pub mod test;
65
66pub use self::{
67    error::Error as MultipartError,
68    field::{Field, LimitExceeded},
69    multipart::Multipart,
70};