Use 'format' in 'raw_upload' example instead of checking Content-Type directly.

This commit is contained in:
Sergio Benitez 2016-10-12 16:48:32 -07:00
parent a9b12568d9
commit 4769b17d13
1 changed files with 3 additions and 8 deletions

View File

@ -5,15 +5,10 @@ extern crate rocket;
use rocket::request::Data;
use rocket::response::Failure;
use rocket::http::{StatusCode, ContentType};
#[post("/upload", data = "<data>")]
fn upload(content_type: ContentType, data: Data) -> Result<String, Failure> {
if !content_type.is_text() {
println!(" => Content-Type of upload must be text. Ignoring.");
return Err(Failure(StatusCode::BadRequest));
}
use rocket::http::StatusCode;
#[post("/upload", format = "text/plain", data = "<data>")]
fn upload(data: Data) -> Result<String, Failure> {
match data.stream_to_file("/tmp/upload.txt") {
Ok(n) => Ok(format!("OK: {} bytes uploaded.", n)),
Err(e) => {