pub fn fetch_formdata<'a, T>(&self,
                                 func: &str,
                                 msg: Value,
                                 mut file: T,
                                 kind: &str,
                                 file_name: &str)
                                 -> impl Future<Item = String, Error = Error> + 'a
        where T: io::Read
    {
        let mut content = Vec::new();

        let mut a = Easy::new();
        let mut form = Form::new();

        // try to read the byte content to a vector
        let _ = file.read_to_end(&mut content).unwrap();

        // add properties
        for (key, val) in msg.as_object().unwrap().iter() {
            form.part(key).contents(format!("{:?}", val).as_bytes()).add().unwrap();
        }

        // add the file
        form.part(kind)
            .buffer(file_name, content)
            .content_type("application/octet-stream")
            .add()
            .unwrap();

        // create a http post request
        a.post(true).unwrap();
        a.httppost(form).unwrap();

        self._fetch(func, a)
    }
/// Creates a new request with some byte content (e.g. a file). The method properties have to be
/// in the formdata setup and cannot be sent as JSON.
Creates a new request with some byte content . The method properties have to be
in the formdata setup and cannot be sent as JSON.
Creates a new request with some byte content . The method properties have to be in the formdata setup and cannot be sent as JSON .
pub fn fetch_formdata<'a, T>(&self,
                                 func: &str,
                                 msg: Value,
                                 mut file: T,
                                 kind: &str,
                                 file_name: &str)
                                 -> impl Future<Item = String, Error = Error> + 'a
        where T: io::Read
    {
        let mut content = Vec::new();
        let mut a = Easy::new();
        let mut form = Form::new();
        // try to read the byte content to a vector
        let _ = file.read_to_end(&mut content).unwrap();
        // add properties
        for (key, val) in msg.as_object().unwrap().iter() {
            form.part(key).contents(format!("{:?}", val).as_bytes()).add().unwrap();
        }
        // add the file
        form.part(kind)
            .buffer(file_name, content)
            .content_type("application/octet-stream")
            .add()
            .unwrap();
        // create a http post request
        a.post(true).unwrap();
        a.httppost(form).unwrap();
        self._fetch(func, a)
    }
pub fn fetch_formdata < ' a , T > ( & self , func : & str , msg : Value , mut file : T , kind : & str , file_name : & str ) -> impl Future < Item = String , Error = Error > + ' a where T : io :: Read { let mut content = Vec :: new ( ) ; let mut a = Easy :: new ( ) ; let mut form = Form :: new ( ) ; // try to read the byte content to a vector let _ = file . read_to_end ( & mut content ) . unwrap ( ) ; // add properties for ( key , val ) in msg . as_object ( ) . unwrap ( ) . iter ( ) { form . part ( key ) . contents ( format ! ( " " val ) . as_bytes ( ) ) . add ( ) . unwrap ( ) ; } // add the file form . part ( kind ) . buffer ( file_name , content ) . content_type ( " " ) . add ( ) . unwrap ( ) ; // create a http post request a . post ( true ) . unwrap ( ) ; a . httppost ( form ) . unwrap ( ) ; self . _fetch ( func , a ) }
Creates a new request with some byte content (e.g.
Creates a new request with some byte content ( e . g .
&self
func
&str
msg
Value
file
T
kind
&str
file_name
&str