A library for retrieving form data from Actix Web's multipart streams. It can stream uploaded files onto the filesystem (its main purpose), but it can also parse associated form data.
Add it to your dependencies. ```toml
[dependencies] actix-web = "0.7.15" actix-form-data = "0.3.2" ```
Require it in your project. ```rust // src/lib.rs or src/main.rs
extern crate form_data;
use form_data::{Field, Form, Value}; ```
First, you'd create a form structure you want to parse from the multipart stream.
rust
let form = Form::new().field("field-name", Field::text());
This creates a form with one required field named "field-name" that will be parsed as text.
Then, pass it to handle_multipart
in your request handler.
rust
let future = form_data::handle_multipart(req.multipart, form);
This returns a Future<Item = Value, Error = form_data::Error>
, which can be used to
fetch your data.
rust
let field_value = match value {
Value::Map(mut hashmap) => {
hashmap.remove("field-name")?
}
_ => return None,
};
```rust /// examples/simple.rs
extern crate actixweb; extern crate formdata; extern crate futures; extern crate mime;
use std::path::PathBuf;
use actixweb::{http, server, App, AsyncResponder, HttpMessage, HttpRequest, HttpResponse, State}; use formdata::{handle_multipart, Error, Field, FilenameGenerator, Form}; use futures::Future;
struct Gen;
impl FilenameGenerator for Gen {
fn next_filename(&self, _: &mime::Mime) -> Option
fn upload( (req, state): (HttpRequest