I am trying to use the basic example to upload a file and some json value (In the example, there is only one name value, but I intend to add more data in futur).
I would like to test it in order to add other functionnalities after but the curl command does not works... Maybe I make a mistake, but I just copy it and change url, etc...
I would like also to test it with Postman for exemple.
But each time json value is not valid. I think it is not a rust problem, but as I need to test my functionnalities... I do not know what is wrong with my json...
Finaly, I found a solution to test without postman...
I post if someone has the same problem... :
#[cfg(test)]
mod tests {
#[test]
fn test_with_file() {
let json = serde_json::json!({
"name": "John Doe"
});
let form = reqwest::blocking::multipart::Form::new()
// .text("json", json.to_string())
.file("file", "FileForTest.tif");
match form {
Ok(form) => {
let part = reqwest::blocking::multipart::Part::text(json.to_string()).mime_str("application/json");
if part.is_err() { assert!(false, "Error, with json part")}
let part = part.unwrap();
// Add the custom part to our form...
let form = form.part("json", part);
let boundary = form.boundary();
print!("boundary is {:#?}", boundary);
let res = reqwest::blocking::Client::new()
.post("http://localhost:8080/api/test")
.header(
"content-type",
format!("multipart/form-data; boundary={}", boundary),
)
.multipart(form) // exact body to send
.send();
print!("RES : {:#?}", res)
}
Err(_) => assert!(false, "Erreur form"),
}
assert!(false);
}
}