#[macro_use]
extern crate rouille;
use std::io;
fn main() {
println!("Now listening on localhost:8000");
rouille::start_server("localhost:8000", move |request| {
rouille::log(&request, io::stdout(), || {
router!(request,
(GET) (/) => {
rouille::Response::html(FORM)
},
(POST) (/submit) => {
let data = try_or_400!(post_input!(request, {
txt: String,
files: Vec<rouille::input::post::BufferedFile>,
}));
println!("Received data: {:?}", data);
rouille::Response::html("Success! <a href=\"/\">Go back</a>.")
},
_ => rouille::Response::empty_404()
)
})
});
}
static FORM: &'static str = r#"
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="submit" method="POST" enctype="multipart/form-data">
<p><input type="text" name="txt" placeholder="Some text" /></p>
<p><input type="file" name="files" multiple /></p>
<p><button>Upload</button></p>
</form>
</body>
</html>
"#;