All Projects → magiclen → rocket-multipart-form-data

magiclen / rocket-multipart-form-data

Licence: MIT license
This crate provides a multipart parser for the Rocket framework.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rocket-multipart-form-data

Rrinlog
Replacing Elasticsearch with Rust and SQLite
Stars: ✭ 129 (+279.41%)
Mutual labels:  rocket
Rocket
Define your release steps 🚀
Stars: ✭ 99 (+191.18%)
Mutual labels:  rocket
juniper rocket
Rocket integration for Juniper, the GraphQL server library for Rust
Stars: ✭ 20 (-41.18%)
Mutual labels:  rocket
Rocket
A web framework for Rust.
Stars: ✭ 15,760 (+46252.94%)
Mutual labels:  rocket
rocket-lamb
A crate to allow running a Rocket webserver as an AWS Lambda Function with API Gateway or an Application Load Balancer
Stars: ✭ 73 (+114.71%)
Mutual labels:  rocket
bin
highly opinionated, minimal pastebin
Stars: ✭ 97 (+185.29%)
Mutual labels:  rocket
Openmotor
An open-source internal ballistics simulator for rocket motor experimenters
Stars: ✭ 107 (+214.71%)
Mutual labels:  rocket
Nasa-And-Spacex-Cooperation
Theme Outer Space
Stars: ✭ 41 (+20.59%)
Mutual labels:  rocket
Unreal-Binary-Builder
An application designed to create installed Unreal Engine builds (aka Rocket builds) from Unreal Engine GitHub source.
Stars: ✭ 554 (+1529.41%)
Mutual labels:  rocket
rocket prometheus
Prometheus fairing and handler for Rocket
Stars: ✭ 38 (+11.76%)
Mutual labels:  rocket
Rust Web Boilerplate
Rust web template for modern web backend applications
Stars: ✭ 211 (+520.59%)
Mutual labels:  rocket
rocket auth
An implementation for an authentication API for Rocket applications.
Stars: ✭ 65 (+91.18%)
Mutual labels:  rocket
streaming-form-data
Streaming parser for multipart/form-data written in Cython
Stars: ✭ 112 (+229.41%)
Mutual labels:  multipart-formdata
Ciapre Xcode Theme
An easy on the eyes Xcode color scheme, ported from Ciapre Sublime Text.
Stars: ✭ 130 (+282.35%)
Mutual labels:  rocket
lohr
Git mirroring daemon
Stars: ✭ 28 (-17.65%)
Mutual labels:  rocket
Plume
Federated blogging application, thanks to ActivityPub (now on https://git.joinplu.me/ — this is just a mirror)
Stars: ✭ 1,615 (+4650%)
Mutual labels:  rocket
MAPLEAF
6-DOF Rocket Flight Simulation Framework
Stars: ✭ 28 (-17.65%)
Mutual labels:  rocket
git-falcon9
No description or website provided.
Stars: ✭ 16 (-52.94%)
Mutual labels:  rocket
FullstackRustDemo
Novelty website + bucket questions implementation.
Stars: ✭ 40 (+17.65%)
Mutual labels:  rocket
multer-rs
An async parser for multipart/form-data content-type in Rust
Stars: ✭ 109 (+220.59%)
Mutual labels:  multipart-formdata

Multipart Form Data for Rocket Framework

CI

This crate provides a multipart parser for the Rocket framework.

Example

#[macro_use] extern crate rocket;

use rocket::Data;
use rocket::http::ContentType;

use rocket_multipart_form_data::{mime, MultipartFormDataOptions, MultipartFormData, MultipartFormDataField, Repetition};

#[post("/", data = "<data>")]
async fn index(content_type: &ContentType, data: Data<'_>) -> &'static str {
    let mut options = MultipartFormDataOptions::with_multipart_form_data_fields(
        vec! [
            MultipartFormDataField::file("photo").content_type_by_string(Some(mime::IMAGE_STAR)).unwrap(),
            MultipartFormDataField::raw("fingerprint").size_limit(4096),
            MultipartFormDataField::text("name"),
            MultipartFormDataField::text("email").repetition(Repetition::fixed(3)),
            MultipartFormDataField::text("email"),
        ]
    );

    let mut multipart_form_data = MultipartFormData::parse(content_type, data, options).await.unwrap();

    let photo = multipart_form_data.files.get("photo"); // Use the get method to preserve file fields from moving out of the MultipartFormData instance in order to delete them automatically when the MultipartFormData instance is being dropped
    let fingerprint = multipart_form_data.raw.remove("fingerprint"); // Use the remove method to move raw fields out of the MultipartFormData instance (recommended)
    let name = multipart_form_data.texts.remove("name"); // Use the remove method to move text fields out of the MultipartFormData instance (recommended)
    let email = multipart_form_data.texts.remove("email");

    if let Some(file_fields) = photo {
        let file_field = &file_fields[0]; // Because we only put one "photo" field to the allowed_fields, the max length of this file_fields is 1.

        let _content_type = &file_field.content_type;
        let _file_name = &file_field.file_name;
        let _path = &file_field.path;

        // You can now deal with the uploaded file.
    }

    if let Some(mut raw_fields) = fingerprint {
        let raw_field = raw_fields.remove(0); // Because we only put one "fingerprint" field to the allowed_fields, the max length of this raw_fields is 1.

        let _content_type = raw_field.content_type;
        let _file_name = raw_field.file_name;
        let _raw = raw_field.raw;

        // You can now deal with the raw data.
    }

    if let Some(mut text_fields) = name {
        let text_field = text_fields.remove(0); // Because we only put one "text" field to the allowed_fields, the max length of this text_fields is 1.

        let _content_type = text_field.content_type;
        let _file_name = text_field.file_name;
        let _text = text_field.text;

        // You can now deal with the text data.
    }

    if let Some(text_fields) = email {
        for text_field in text_fields { // We put "email" field to the allowed_fields for two times and let the first time repeat for 3 times, so the max length of this text_fields is 4.
            let _content_type = text_field.content_type;
            let _file_name = text_field.file_name;
            let _text = text_field.text;

            // You can now deal with the text data.
        }
    }

    "ok"
}

Also see examples.

Crates.io

https://crates.io/crates/rocket-multipart-form-data

Documentation

https://docs.rs/rocket-multipart-form-data

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].