Client- and server-side abstractions for HTTP file uploads (POST requests with Content-Type: multipart/form-data
).
Provides integration with Hyper via the hyper
feature. More to come!
In your Cargo.toml
:
```toml
hyper
and url
crates:[dependencies] hyper = "" url = ""
[dependencies.multipart] version = "0.2"
hyper
feature enables trait impls for Hyper's request objects.features = ["hyper"] ```
Client-side example (using Hyper): ```rust extern crate hyper; extern crate multipart; extern crate url;
use hyper::client::request::Request; use hyper::method::Method;
use multipart::client::Multipart;
use url::Url;
fn main() { let url = Url::parse("127.0.0.1").unwrap(); let request = Request::new(Method::Post, url).unwrap();
let mut response = Multipart::from_request(request).unwrap()
.write_text("hello", "world")
.write_file("my_file", "my_text_data.txt")
.send().unwrap();
// Read response...
} ```
Server-side example (using Hyper): ```rust use hyper::net::Fresh; use hyper::server::{Server, Request, Response};
use multipart::server::Multipart; use multipart::server::hyper::Switch;
fn handle_regular<'a, 'k>(req: Request<'a, 'k>, res: Response<'a, Fresh>) { // handle things here }
fn handlemultipart<'a, 'k>(mut multi: Multipart
fn main() { Server::http("0.0.0.0:0").unwrap() .handle(Switch::new(handleregular, handlemultipart)) .unwrap(); } ```