#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate rocket_multipart_form_data;
use rocket::Data;
use rocket::http::ContentType;
use rocket_multipart_form_data::{MultipartFormDataOptions, MultipartFormData, MultipartFormDataField, FileField, TextField, RawField};
#[post("/", data = "<data>")]
fn index(content_type: &ContentType, data: Data) -> &'static str
{
let mut options = MultipartFormDataOptions::new();
options.allowed_fields.push(MultipartFormDataField::file("photo").content_type_by_string(Some("image/*")).unwrap());
options.allowed_fields.push(MultipartFormDataField::raw("fingerprint").size_limit(4096));
options.allowed_fields.push(MultipartFormDataField::text("name"));
options.allowed_fields.push(MultipartFormDataField::text("array_max_length_3"));
options.allowed_fields.push(MultipartFormDataField::text("array_max_length_3"));
options.allowed_fields.push(MultipartFormDataField::text("array_max_length_3"));
let multipart_form_data = MultipartFormData::parse(content_type, data, options).unwrap();
let photo = multipart_form_data.files.get(&"photo".to_string());
let fingerprint = multipart_form_data.raw.get(&"fingerprint".to_string());
let name = multipart_form_data.texts.get(&"name".to_string());
let array = multipart_form_data.texts.get(&"array_max_length_3".to_string());
if let Some(photo) = photo {
match photo {
FileField::Single(file) => {
let _content_type = &file.content_type;
let _file_name = &file.file_name;
let _path = &file.path;
}
FileField::Multiple(_files) => {
}
}
}
if let Some(fingerprint) = fingerprint {
match fingerprint {
RawField::Single(raw) => {
let _content_type = &raw.content_type;
let _file_name = &raw.file_name;
let _raw = &raw.raw;
}
RawField::Multiple(_bytes) => {
}
}
}
if let Some(name) = name {
match name {
TextField::Single(text) => {
let _content_type = &text.content_type;
let _file_name = &text.file_name;
let _text = &text.text;
}
TextField::Multiple(_texts) => {
}
}
}
if let Some(array) = array {
match array {
TextField::Single(text) => {
let _content_type = &text.content_type;
let _file_name = &text.file_name;
let _text = &text.text;
}
TextField::Multiple(texts) => {
for text in texts { let _content_type = &text.content_type;
let _file_name = &text.file_name;
let _text = &text.text;
}
}
}
}
"ok"
}