36 releases

0.7.2 Jul 6, 2024
0.6.2 Jun 8, 2024
0.6.1 Aug 29, 2023
0.6.0 Feb 26, 2023
0.1.2 Jun 2, 2019

#216 in HTTP server

Download history 26431/week @ 2024-04-01 24221/week @ 2024-04-08 26736/week @ 2024-04-15 34478/week @ 2024-04-22 35086/week @ 2024-04-29 30003/week @ 2024-05-06 37212/week @ 2024-05-13 37031/week @ 2024-05-20 35961/week @ 2024-05-27 40490/week @ 2024-06-03 37616/week @ 2024-06-10 35962/week @ 2024-06-17 39508/week @ 2024-06-24 35740/week @ 2024-07-01 34105/week @ 2024-07-08 32581/week @ 2024-07-15

143,068 downloads per month
Used in 63 crates (56 directly)

MIT/Apache

1.5MB
35K SLoC

actix-multipart

crates.io Documentation Version MIT or Apache 2.0 licensed
dependency status Download Chat on Discord

Multipart form support for Actix Web.

Examples

use actix_web::{post, App, HttpServer, Responder};

use actix_multipart::form::{json::Json as MPJson, tempfile::TempFile, MultipartForm};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Metadata {
    name: String,
}

#[derive(Debug, MultipartForm)]
struct UploadForm {
    #[multipart(limit = "100MB")]
    file: TempFile,
    json: MPJson<Metadata>,
}

#[post("/videos")]
pub async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Responder {
    format!(
        "Uploaded file {}, with size: {}",
        form.json.name, form.file.size
    )
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(move || App::new().service(post_video))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}

cURL request:

curl -v --request POST \
  --url http://localhost:8080/videos \
  -F 'json={"name": "Cargo.lock"};type=application/json' \
  -F file=@./Cargo.lock

More available in the examples repo →

Dependencies

~15–27MB
~489K SLoC