Easy to use multipart forms for actix-web

Overview

Actix Easy Multipart

Build status crates.io docs.rs

Easy to use Multipart Forms for actix-web.

File uploads are written to disk as temporary files similar to the way the $_FILES variable works in PHP.

Example

use actix_web::Responder;
use actix_easy_multipart::{MultipartFile, FromMultipart};
use actix_easy_multipart::extractor::MultipartForm;

#[derive(FromMultipart)]
struct Upload {
   description: String,
   image: MultipartFile,
}

async fn route(form: MultipartForm<Upload>) -> impl Responder {
    format!("Received image of size: {}", form.image.size)
}
You might also like...
Cookiecutter Rust Actix template for jumpstarting production-ready projects quickly.

Cookiecutter actix simple clean architecture This is a reusable Rust Cookiecutter template. The project is based on Actix web in combination with Dies

Fahrenheit-celsius converter using actix

fahrenheit-celsius-converter Simple http Fahrenheit/Celsius/Kelvin converter using actix-web. Note This is a toy project, not yet finished. It's not r

Easy-to-use string interner crate for Rust.

🪐 tiny_interner crate. ~300 lines of Rust code that implement string internering for your programming language compiler. Example fn main() { let

A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. :zap::crab:
A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. :zap::crab:

binserve ⚡ 🦀 A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. 🔥 UPDATE: N

Simple and fast web server

see Overview Simple and fast web server as a single executable with no extra dependencies required. Features Built with Tokio and Hyper TLS encryption

A flexible web framework that promotes stability, safety, security and speed.

A flexible web framework that promotes stability, safety, security and speed. Features Stability focused. All releases target stable Rust. This will n

JSON Web Token implementation in Rust.

Frank JWT Implementation of JSON Web Tokens in Rust. Algorithms and features supported HS256 HS384 HS512 RS256 RS384 RS512 ES256 ES384 ES512 Sign Veri

An Extensible, Concurrent Web Framework for Rust

Iron Extensible, Concurrency Focused Web Development in Rust. Response Timer Example Note: This example works with the current iron code in this repos

An expressjs inspired web framework for Rust

nickel.rs nickel.rs is a simple and lightweight foundation for web applications written in Rust. Its API is inspired by the popular express framework

Comments
  • Upload files larger than 256kb

    Upload files larger than 256kb

    When I use this library and I try to upload a file larger than the default 256kb file limit, I get the following error:

    Multipart error: Payload reached size limit.
    

    This is the code I use for the endpoint:

    #[derive(FromMultipart, ToSchema)]
    struct Payload {
        other: String,
        #[schema(value_type = String, format = Binary)]
        payload: File,
    }
    
    #[utoipa::path(
        request_body(content = Payload, content_type = "multipart/form-data"),
        responses(
            (status = 201, description = "Payload successfully uploaded"),
        )
    )]
    #[post("/payload/upload")]
    async fn task_upload(metadata: MultipartForm<Payload>) -> impl Responder {
        println!("{}, {:?}", metadata.other, metadata.payload.filename);
    
        HttpResponse::Ok()
    }
    

    To fix this, I've tried to change the default size for both actix and this library:

    HttpServer::new(move || {
        App::new()
            .app_data(state.clone())
            .app_data(actix_web::web::PayloadConfig::new(500 * 1024 * 1024))
            .app_data(MultipartFormConfig::default().file_limit(500 * 1024 * 1024))
            .service(
                SwaggerUi::new("/swagger-ui/{_:.*}").url("/api-doc/openapi.json", openapi.clone()),
            )
            .service(task_upload)
    })
    .bind(("0.0.0.0", 8080))?
    .run()
    .await
    

    Nothing seems to help. When I use Multipart and stream directly from actix, the file limit error does not kick in. I'm not sure if the issue happens in this library, or if it is actix as this is unfortunately a part of the framework that lacks documentation.

    opened by Nohac 6
  • updated for usage in actix-web 4.0.0-beta.21

    updated for usage in actix-web 4.0.0-beta.21

    Hello,

    I am very happy about this library. It works great and is so much easier to use than handling the multipart data yourself. I ran into issues with using actix-web 4.0.0 because of the tokio runtime and the FromRequest trait changes. I forked your library and somehow fixed it. I literally ruined your code, but might consider fixing it up and merging it into another branch for other people to use. 👍🏼

    Greetings, 1zuna

    opened by 1zun4 4
  • persist unavailable?

    persist unavailable?

    code

    #[derive(FromMultipart)]
    pub struct Upload {
        name: String,
        file: File,
    }
    
    #[post("/upload")]
    pub async fn batch_upload_photo(
        form: MultipartForm<Upload>,
    ) -> anyhow::Result<impl Responder, ServiceError> {
        let new_file = form.file.file.persist("./upload/a.png");
    
        println!("file {:?}", &form.file.file);
    }
    

    error

    cannot move out of dereference of `MultipartForm<Upload>`
    

    image

    opened by rustdreamer 2
  • Example of form with several fields and a binary file

    Example of form with several fields and a binary file

    As of now, the example shows how to handle a multipart form that has just one text field: #[derive(MultipartForm)] struct Upload { text: Text<String>, } Could you please update the example or create a new one showing how to handle a form that has several text fields and a binary file? This is the typical example of a user using a form to submit some information alongside a binary file. @jacob-pro, this is valuable work, should be pulled into the official actix web multipart package.

    opened by vbocan 1
Owner
Jacob Halsey
Software Engineer @Oracle Cloud. (Personal account)
Jacob Halsey
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust Features Supports HTTP/1.x and HTTP/2 Streaming and pipelining

Actix 16.3k Jan 8, 2023
A starter template for actix-web projects that feels very Django-esque. Avoid the boring stuff and move faster.

Jelly A.K.A, the actix-web starter you probably wish you had. This is provided as-is, and anyone is free to extend it or rework it as they desire - ju

SecretKeys 198 Dec 15, 2022
Extension for actix-web to validate user permissions

actix-web-grants Extension for actix-web to validate user permissions. To check user access to specific services, you can use built-in proc-macro, Per

Artem Medvedev 114 Dec 22, 2022
Add Facebook and Google authentication to your HTTP REST API in Actix-web

I created this project while learning Rust. Project shows how to handle Facebook and Google token verification in Rust using Actix-Web. Hope this help

null 37 Dec 31, 2022
In-progress extractors and middleware for Actix Web

actix-web-lab Experimental extractors, middleware, and other extras for possible inclusion in Actix Web. Things To Know About This Crate It will never

Rob Ede 51 Dec 20, 2022
Example Blog using Rust, Actix Web, HTMX, Mustache

Actix Blog An example blog built with Actix. It uses htmx and handlebar templates. Running To run the blog, you need to have a recent version of Rust

Dru Jensen 2 Nov 11, 2022
Actix-web wrapper for garde, a Rust validation library.

Garde-actix-web   Actix-web wrapper for garde, a Rust validation library. Installation Usage example Feature flags About us Installation [dependencies

Netwo 5 Sep 8, 2023
Static Web Server - a very small and fast production-ready web server suitable to serve static web files or assets

Static Web Server (or SWS abbreviated) is a very small and fast production-ready web server suitable to serve static web files or assets.

Jose Quintana 496 Jan 2, 2023
Example Actix 2.x REST application implementing many features

Rust/Actix Example An Actix 2.0 REST server using the Rust language. Motivation Actix Web is a fast, powerful web framework for building web applicati

David D. 238 Dec 31, 2022
Basic Actix + Diesel + Postgres REST API

Actix-Crud Basic Actix + Diesel + Postgres REST API Setup Install and setup PostgreSQL Set DATABASE_URL environment variable or specify in .env file g

Aathif Naseer 4 Sep 23, 2022