awmp

Docs Crates.io

A convenience library for working with multipart/form-data in actix-web 1.x, 2.x, or 3.x.

This library uses actix-multipart internally, and is not a replacement for actix-multipart. It saves multipart file data to tempfiles and collects text data, handling all blocking I/O operations.

Provides some configuration options in PartsConfig:

Usage

This crate supports both major versions of actix-web, 1.x, 2.x, and 3.x. It supports 3.x by default.

To use with actix-web 1.x, add the following to your Cargo.toml:

toml awmp = { version = "0.6", default-features = false, features = ["v1"] }

Example

```rust use actix_web::{web, App, Error, FromRequest, HttpResponse, HttpServer};

async fn upload(mut parts: awmp::Parts) -> Result { let qs = parts.texts.toquerystring();

let file_parts = parts
    .files
    .take("file")
    .pop()
    .and_then(|f| f.persist("/tmp").ok())
    .map(|f| format!("File uploaded to: {}", f.display()))
    .unwrap_or_default();

let body = [format!("Text parts: {}", &qs), file_parts].join(", ");

Ok(actix_web::HttpResponse::Ok().body(body))

}

[actix_rt::main]

async fn main() -> Result<(), std::io::Error> { actixweb::HttpServer::new(move || { actixweb::App::new() .data(awmp::Parts::configure(|cfg| cfg.withfilelimit(1000000))) .route("/", actix_web::web::post().to(upload)) }) .bind("0.0.0.0:3000")? .run() .await } ```

Current version: 0.6.0

License: MIT