#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use std::path::{Path, PathBuf};
use rocket::response::NamedFile;
use rocket::response::content::Html;
use rocket::http::ContentType;
use rocket_upload::MultipartDatas;
#[post("/upload/<userid>", data = "<data>")]
fn upload(userid: String, content_type: &ContentType, data: MultipartDatas) -> Html<String>
{
let mut result=format!("UserID:{}<br>",userid);
result = format!("{}{:?}<br>",result,content_type);
for t in data.texts {
result = format!("{}FieldName:{} --- FieldValue:{}<br>",result,t.key,t.value);
}
for f in data.files {
result = format!("{}FieldName:{} --- FileName:{} --- StoragePath:{}<br>",
result,f.name,f.filename,f.path);
f.persist(Path::new("upload"));
}
Html(format!("<html><head></head><body>upload coming...<br>{}</body></html>",result))
}
#[get("/")]
pub fn index() -> Option<NamedFile> {
NamedFile::open("static/index.html").ok()
}
#[get("/static/<file..>", rank = 2)]
pub fn static_files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).ok()
}
fn rocket() -> rocket::Rocket {
rocket::ignite()
.mount("/", routes![index, static_files, upload])
}
fn main() {
rocket().launch();
}