I'm attempting to upload video files to Dustloop, a mediawiki page for ArcSys games, and I've managed to get all the way to acquiring a CSRF token to be able to upload, but I'm struggling on the last part. I believe I have correctly done everything else, But I'm not able to get the file part correctly.
async fn upload_file(client: &mut reqwest::Client, csrf_token: String) {
let mut params = HashMap::new();
params.insert("action", "upload");
params.insert("filename", "maria-artemis-test.webm");
params.insert("comment", "API test file.");
params.insert("token", csrf_token.as_str());
params.insert("format", "json");
let url = reqwest::Url::parse("https://dustloop.com/wiki/api.php").unwrap();
let file: Vec<u8> = fs::read("output.webm").unwrap();
let file_part = Part::bytes(file).file_name("output.webm").mime_str("video/webm").unwrap();
let form = Form::new().part("video", file_part);
let response = client.post(url).form(¶ms).header(reqwest::header::CONTENT_TYPE, "multipart/form-data").multipart(form).send().await.unwrap();
println!("{:?}", response.headers());
println!("{}", response.text().await.unwrap());
}
this is my current code so far, taken from simmons/reqwest-upload-example.rs, but this doesnt seem to function for me.
The mediawiki API docs (same API as dustloop) has a python example, and I think ive gotten as close as I can
Any assistance on getting this to correctly upload files? Currently it just dumps the API documentation page back to me, not even responding with a json response (although if I remove .multipart, it does respond with JSON, so theres something there going wrong I think). Everything else should be fine, it is just the multipart process that goes wrong.