From c6b6bd1af72554f62315090e26b3b1510572a792 Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Wed, 24 Aug 2022 17:02:13 +0200 Subject: [PATCH] fix(0x0): fix builder error --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 2 +- src/null_pointer/mod.rs | 13 +++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8bfc98f..672afd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,6 +1011,16 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -1463,6 +1473,7 @@ dependencies = [ "lazy_static", "log", "mime", + "mime_guess", "percent-encoding", "pin-project-lite", "rustls", @@ -1943,6 +1954,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.8" diff --git a/Cargo.toml b/Cargo.toml index 972478d..5d9a16a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ validator = "0.16.0" thiserror = "1.0.32" serde_json = "1.0.85" serde = { version = "1.0.144", features = ["derive"] } -reqwest = { version = "0.11.11", default-features = false, features = ["json", "rustls-tls"] } +reqwest = { version = "0.11.11", default-features = false, features = ["json", "rustls-tls", "multipart"] } [dev-dependencies] tokio = { version = "1.20.1", features = ["macros", "rt-multi-thread"] } diff --git a/src/null_pointer/mod.rs b/src/null_pointer/mod.rs index 6cb5947..cfe87d1 100644 --- a/src/null_pointer/mod.rs +++ b/src/null_pointer/mod.rs @@ -38,14 +38,11 @@ impl NullPointer { /// } /// ``` pub async fn upload(&self, path: &str) -> Result { - // create http form (hashmap) - let mut form = HashMap::new(); + let mut bytes = Vec::new(); // check if the specified file exists if not then check if it is a url if std::path::Path::new(path).exists() { - let bytes = std::fs::read(path)?; - - form.insert("file", bytes); + bytes = std::fs::read(path)?; } // validate url adress else { @@ -65,7 +62,11 @@ impl NullPointer { format!("Imgur/{:?}", env!("CARGO_PKG_VERSION")), ); - req = req.form(&form); + let part = reqwest::multipart::Part::bytes(bytes); + + let form = reqwest::multipart::Form::new().part("file", part); + + req = req.multipart(form); // build Request let req = req.build()?;