aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-16 23:03:33 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-16 23:03:33 +0100
commite4e75aa8c85b15b91ef57b4288e620bf3d906500 (patch)
tree09db58afad131bbf86629ccd1378f213722403cc /src
parent8294f640abc38611007cdc2697e5117b6c1663b9 (diff)
downloadrust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.tar.gz
rust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.tar.bz2
rust-zotapi-e4e75aa8c85b15b91ef57b4288e620bf3d906500.zip
Upload one file should now work.
Diffstat (limited to 'src')
-rw-r--r--src/client.rs17
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() {