2016-10-12 07:14:42 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
use rocket::request::Data;
|
|
|
|
use rocket::response::Failure;
|
2016-10-12 23:48:32 +00:00
|
|
|
use rocket::http::StatusCode;
|
2016-10-12 07:14:42 +00:00
|
|
|
|
2016-10-12 23:48:32 +00:00
|
|
|
#[post("/upload", format = "text/plain", data = "<data>")]
|
|
|
|
fn upload(data: Data) -> Result<String, Failure> {
|
2016-10-12 07:14:42 +00:00
|
|
|
match data.stream_to_file("/tmp/upload.txt") {
|
|
|
|
Ok(n) => Ok(format!("OK: {} bytes uploaded.", n)),
|
|
|
|
Err(e) => {
|
|
|
|
println!(" => Failed writing to file: {:?}.", e);
|
|
|
|
return Err(Failure(StatusCode::InternalServerError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
fn index() -> &'static str {
|
|
|
|
"Upload your text files by POSTing them to /upload."
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket::ignite().mount("/", routes![index, upload]).launch();
|
|
|
|
}
|