From e4e75aa8c85b15b91ef57b4288e620bf3d906500 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 16 Dec 2018 23:03:33 +0100 Subject: Upload one file should now work. --- src/client.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') 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(&self, path: &str, _data: &T, _files: &Vec<&str>) -> Result - where T: Serialize, + pub fn post_multipart(&self, path: &str, data: &BTreeMap<&str, &str>, files: &Vec<&str>) -> Result { 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() { -- cgit v1.2.3