diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-16 23:03:33 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-16 23:03:33 +0100 |
commit | e4e75aa8c85b15b91ef57b4288e620bf3d906500 (patch) | |
tree | 09db58afad131bbf86629ccd1378f213722403cc /src/client.rs | |
parent | 8294f640abc38611007cdc2697e5117b6c1663b9 (diff) | |
download | rust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.tar.gz rust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.tar.bz2 rust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.zip |
Upload one file should now work.
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/client.rs b/src/client.rs index 374cfb2..3dbca36 100644 --- a/src/client.rs +++ b/src/client.rs @@ -23,6 +23,7 @@ use reqwest::{ }; use serde::Serialize; use serde_urlencoded; +use std::collections::BTreeMap; use std::io::Read; use abook::AbookFetcher; use abconfig::ABConfigFetcher; @@ -133,17 +134,23 @@ impl Client { } } - pub fn post_multipart<T>(&self, path: &str, _data: &T, _files: &Vec<&str>) -> Result<String, Error> - where T: Serialize, + pub fn post_multipart(&self, path: &str, data: &BTreeMap<&str, &str>, files: &Vec<&str>) -> Result<String, Error> { let url = self.url(path, &()); - let f = reqwest::multipart::Form::new() - .text("balle", "klorin"); + let mut form = reqwest::multipart::Form::new(); + + for (key, value) in data.iter() { + form = form.text(key.to_string(), value.to_string()); + } + + for f in files.iter() { + form = form.file("files", f).unwrap(); + } let res = self.inner.post(&url) .basic_auth(self.user.clone(), Some(self.pw.clone())) .header(CONTENT_TYPE, "multipart/form-data") - .multipart(f) + .multipart(form) .send()?; match res.status() { |