Rocket/examples/raw_upload/src/main.rs

28 lines
530 B
Rust
Raw Normal View History

#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
2017-05-25 05:56:52 +00:00
#[cfg(test)] mod tests;
2017-05-25 05:56:52 +00:00
use std::io;
use rocket::Data;
#[post("/upload", format = "text/plain", data = "<data>")]
2017-05-25 05:56:52 +00:00
fn upload(data: Data) -> io::Result<String> {
data.stream_to_file("/tmp/upload.txt").map(|n| n.to_string())
}
#[get("/")]
fn index() -> &'static str {
"Upload your text files by POSTing them to /upload."
}
2017-05-25 05:56:52 +00:00
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index, upload])
}
fn main() {
2017-05-25 05:56:52 +00:00
rocket().launch();
}