{"id":13822400,"url":"https://github.com/rwf2/multer","last_synced_at":"2025-12-12T12:42:42.470Z","repository":{"id":39580067,"uuid":"262161085","full_name":"rwf2/multer","owner":"rwf2","description":"An async parser for multipart/form-data content-type in Rust","archived":false,"fork":false,"pushed_at":"2024-05-04T01:46:28.000Z","size":181,"stargazers_count":158,"open_issues_count":7,"forks_count":39,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-12T00:07:08.000Z","etag":null,"topics":["async","multipart-formdata","multipart-parser","multipart-uploads","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rwf2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rwf2","open_collective":"rwf2"}},"created_at":"2020-05-07T21:20:45.000Z","updated_at":"2024-12-07T00:37:48.000Z","dependencies_parsed_at":"2024-05-04T01:57:43.893Z","dependency_job_id":null,"html_url":"https://github.com/rwf2/multer","commit_stats":{"total_commits":86,"total_committers":14,"mean_commits":6.142857142857143,"dds":0.5697674418604651,"last_synced_commit":"d30e0833d1ae5748d7a2fb459d9d9b28e8b2ddb8"},"previous_names":["rwf2/multer-rs","rousan/multer-rs","rwf2/multer"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwf2%2Fmulter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwf2%2Fmulter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwf2%2Fmulter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwf2%2Fmulter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwf2","download_url":"https://codeload.github.com/rwf2/multer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464897,"owners_count":22075571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","multipart-formdata","multipart-parser","multipart-uploads","rust"],"created_at":"2024-08-04T08:01:58.913Z","updated_at":"2025-12-12T12:42:42.403Z","avatar_url":"https://github.com/rwf2.png","language":"Rust","funding_links":["https://github.com/sponsors/rwf2","https://opencollective.com/rwf2"],"categories":["Rust"],"sub_categories":[],"readme":"[![GitHub Actions Status](https://github.com/rousan/multer-rs/actions/workflows/test.yml/badge.svg)](https://github.com/rousan/multer-rs/actions)\n[![crates.io](https://img.shields.io/crates/v/multer.svg)](https://crates.io/crates/multer)\n[![Documentation](https://docs.rs/multer/badge.svg)](https://docs.rs/multer)\n[![MIT](https://img.shields.io/crates/l/multer.svg)](./LICENSE)\n\n# multer-rs\n\nAn async parser for `multipart/form-data` content-type in Rust.\n\nIt accepts a [`Stream`](https://docs.rs/futures/0.3/futures/stream/trait.Stream.html) of [`Bytes`](https://docs.rs/bytes/1/bytes/struct.Bytes.html) as\na source, so that It can be plugged into any async Rust environment e.g. any async server.\n\n[Docs](https://docs.rs/multer)\n\n## Install    \n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nmulter = \"2.0\"\n```\n\n# Basic Example\n\n```rust\nuse bytes::Bytes;\nuse futures::stream::Stream;\n// Import multer types.\nuse multer::Multipart;\nuse std::convert::Infallible;\nuse futures::stream::once;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Generate a byte stream and the boundary from somewhere e.g. server request body.\n    let (stream, boundary) = get_byte_stream_from_somewhere().await;\n\n    // Create a `Multipart` instance from that byte stream and the boundary.\n    let mut multipart = Multipart::new(stream, boundary);\n\n    // Iterate over the fields, use `next_field()` to get the next field.\n    while let Some(mut field) = multipart.next_field().await? {\n        // Get field name.\n        let name = field.name();\n        // Get the field's filename if provided in \"Content-Disposition\" header.\n        let file_name = field.file_name();\n\n        println!(\"Name: {:?}, File Name: {:?}\", name, file_name);\n\n        // Process the field data chunks e.g. store them in a file.\n        while let Some(chunk) = field.chunk().await? {\n            // Do something with field chunk.\n            println!(\"Chunk: {:?}\", chunk);\n        }\n    }\n\n    Ok(())\n}\n\n// Generate a byte stream and the boundary from somewhere e.g. server request body.\nasync fn get_byte_stream_from_somewhere() -\u003e (impl Stream\u003cItem = Result\u003cBytes, Infallible\u003e\u003e, \u0026'static str) {\n    let data = \"--X-BOUNDARY\\r\\nContent-Disposition: form-data; name=\\\"my_text_field\\\"\\r\\n\\r\\nabcd\\r\\n--X-BOUNDARY--\\r\\n\";\n    let stream = once(async move { Result::\u003cBytes, Infallible\u003e::Ok(Bytes::from(data)) });\n    \n    (stream, \"X-BOUNDARY\")\n}\n``` \n\n## Prevent Denial of Service (DoS) Attacks\n\nThis crate also provides some APIs to prevent potential DoS attacks with fine grained control. It's recommended to add some constraints\non field (specially text field) size to prevent DoS attacks exhausting the server's memory.\n\nAn example:\n\n```rust\nuse multer::{Multipart, Constraints, SizeLimit};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Create some constraints to be applied to the fields to prevent DoS attack.\n    let constraints = Constraints::new()\n         // We only accept `my_text_field` and `my_file_field` fields,\n         // For any unknown field, we will throw an error.\n         .allowed_fields(vec![\"my_text_field\", \"my_file_field\"])\n         .size_limit(\n             SizeLimit::new()\n                 // Set 15mb as size limit for the whole stream body.\n                 .whole_stream(15 * 1024 * 1024)\n                 // Set 10mb as size limit for all fields.\n                 .per_field(10 * 1024 * 1024)\n                 // Set 30kb as size limit for our text field only.\n                 .for_field(\"my_text_field\", 30 * 1024),\n         );\n\n    // Create a `Multipart` instance from a stream and the constraints.\n    let mut multipart = Multipart::with_constraints(some_stream, \"X-BOUNDARY\", constraints);\n\n    while let Some(field) = multipart.next_field().await.unwrap() {\n        let content = field.text().await.unwrap();\n        assert_eq!(content, \"abcd\");\n    } \n   \n    Ok(())\n}\n```\n\n## Usage with [hyper.rs](https://hyper.rs/) server\n\nAn [example](https://github.com/rousan/multer-rs/blob/master/examples/hyper_server_example.rs) showing usage with [hyper.rs](https://hyper.rs/).\n\nFor more examples, please visit [examples](https://github.com/rousan/multer-rs/tree/master/examples).\n\n## Contributing\n\nYour PRs and suggestions are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwf2%2Fmulter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwf2%2Fmulter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwf2%2Fmulter/lists"}