I want to parse a HTTP POST in Rocket using a struct. Upon submitting the form it fails.
I read the body data example and have this code.
#[derive(FromForm)]
struct ConvertFile {
name: String,
filename: String
}
#[post("/submit", format = "multipart/form-data", data = "<form>")]
fn submit(form: Form<ConvertFile>) {
println!("form field: {}", form.get().name);
}
I submit using curl:
curl -H "Content-Type: multipart/form-data" -F "name=Claus" -F "filename=claus.jpg" http://localhost:8000/submit
and the Rocket console responds with
multipart/form-data; boundary=------------------------8495649d6ed34d20:
=> Matched: POST /submit multipart/form-data
=> Warning: Form data does not have form content type.
=> Outcome: Forward
=> Error: No matching routes for POST /submit multipart/form-data; boundary=------------------------8495649d6ed34d2.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
I want to submit a file hence the multipart/form-data
. When trying to find the reason, I used a String
in the struct to make it simpler. So first it responds with a Matched:
and then no matching routes.
This simpler POST works:
#[post("/convert", format = "text/plain", data = "<file>")]
fn convert_file(file: String) {
println!("file: {}", file);
}
I am using the latest nightly Rust with rustup.
What am I doing wrong?