fn upload_asset<T>(&self, client: &HyperClient, req_data: T,
                       asset_data: &[u8], asset_type: ContentType)
                       -> BerylliumFuture<AssetData>
        where T: Serialize
    {
        // Start writing multipart data
        let mut writer = MultipartWriter::new(MULTIPART_BOUNDARY);

        // Asset upload request JSON
        writer.add_boundary();
        writer.add_header(ContentType::json());
        let json_bytes = future_try!(serde_json::to_vec(&req_data));
        writer.add_header(ContentLength(json_bytes.len() as u64));
        writer.add_line();
        writer.add_body(&json_bytes);

        // AES-256-CBC encrypted asset data
        writer.add_boundary();
        writer.add_header(asset_type);
        writer.add_header(ContentLength(asset_data.len() as u64));
        let hash = utils::md5_hash(&asset_data);
        writer.add_header(ContentMd5(base64::encode(&hash)));
        writer.add_line();
        writer.add_body(&asset_data);
        writer.add_boundary();
        let multipart = writer.finish();

        let mut request = self.prepare_request_for_url(Method::Post, "/bots/assets");
        request.headers_mut().set(ContentType(MULTIPART_MIXED.clone()));
        request.headers_mut().set(ContentLength(multipart.len() as u64));
        request.set_body(multipart);

        let f = HttpsClient::request_with_request(client, request)
                            .and_then(|(code, headers, body)| {
            utils::acquire_body_with_err(&headers, body).and_then(move |vec| {
                if code.is_success() {
                    info!("Successfully uploaded asset.");
                    let res = serde_json::from_slice::<AssetData>(&vec)
                                         .map_err(BerylliumError::from);
                    future::result(res)
                } else {
                    let res = serde_json::from_slice::<SerdeValue>(&vec)
                                         .map_err(BerylliumError::from);
                    let msg = format!("Error uploading asset. Response: {:?}", res);
                    future::err(BerylliumError::Other(msg))
                }
            })
        });

        Box::new(f)
    }
/// Upload a given asset to Wire servers and return the asset key and token.
/// Note that the `asset_data` is encrypted at this point.
Upload a given asset to Wire servers and return the asset key and token.
Note that the `asset_data` is encrypted at this point.
Upload a given asset to Wire servers and return the asset key and token . Note that the ` asset_data ` is encrypted at this point .
fn upload_asset<T>(&self, client: &HyperClient, req_data: T,
                       asset_data: &[u8], asset_type: ContentType)
                       -> BerylliumFuture<AssetData>
        where T: Serialize
    {
        // Start writing multipart data
        let mut writer = MultipartWriter::new(MULTIPART_BOUNDARY);
        // Asset upload request JSON
        writer.add_boundary();
        writer.add_header(ContentType::json());
        let json_bytes = future_try!(serde_json::to_vec(&req_data));
        writer.add_header(ContentLength(json_bytes.len() as u64));
        writer.add_line();
        writer.add_body(&json_bytes);
        // AES-256-CBC encrypted asset data
        writer.add_boundary();
        writer.add_header(asset_type);
        writer.add_header(ContentLength(asset_data.len() as u64));
        let hash = utils::md5_hash(&asset_data);
        writer.add_header(ContentMd5(base64::encode(&hash)));
        writer.add_line();
        writer.add_body(&asset_data);
        writer.add_boundary();
        let multipart = writer.finish();
        let mut request = self.prepare_request_for_url(Method::Post, "/bots/assets");
        request.headers_mut().set(ContentType(MULTIPART_MIXED.clone()));
        request.headers_mut().set(ContentLength(multipart.len() as u64));
        request.set_body(multipart);
        let f = HttpsClient::request_with_request(client, request)
                            .and_then(|(code, headers, body)| {
            utils::acquire_body_with_err(&headers, body).and_then(move |vec| {
                if code.is_success() {
                    info!("Successfully uploaded asset.");
                    let res = serde_json::from_slice::<AssetData>(&vec)
                                         .map_err(BerylliumError::from);
                    future::result(res)
                } else {
                    let res = serde_json::from_slice::<SerdeValue>(&vec)
                                         .map_err(BerylliumError::from);
                    let msg = format!("Error uploading asset. Response: {:?}", res);
                    future::err(BerylliumError::Other(msg))
                }
            })
        });
        Box::new(f)
    }
fn upload_asset < T > ( & self , client : & HyperClient , req_data : T , asset_data : & [ u8 ] , asset_type : ContentType ) -> BerylliumFuture < AssetData > where T : Serialize { // Start writing multipart data let mut writer = MultipartWriter :: new ( MULTIPART_BOUNDARY ) ; // Asset upload request JSON writer . add_boundary ( ) ; writer . add_header ( ContentType :: json ( ) ) ; let json_bytes = future_try ! ( serde_json to_vec ( req_data ) ) ; writer . add_header ( ContentLength ( json_bytes . len ( ) as u64 ) ) ; writer . add_line ( ) ; writer . add_body ( & json_bytes ) ; // AES-256-CBC encrypted asset data writer . add_boundary ( ) ; writer . add_header ( asset_type ) ; writer . add_header ( ContentLength ( asset_data . len ( ) as u64 ) ) ; let hash = utils :: md5_hash ( & asset_data ) ; writer . add_header ( ContentMd5 ( base64 :: encode ( & hash ) ) ) ; writer . add_line ( ) ; writer . add_body ( & asset_data ) ; writer . add_boundary ( ) ; let multipart = writer . finish ( ) ; let mut request = self . prepare_request_for_url ( Method :: Post , " " ) ; request . headers_mut ( ) . set ( ContentType ( MULTIPART_MIXED . clone ( ) ) ) ; request . headers_mut ( ) . set ( ContentLength ( multipart . len ( ) as u64 ) ) ; request . set_body ( multipart ) ; let f = HttpsClient :: request_with_request ( client , request ) . and_then ( | ( code , headers , body ) | { utils :: acquire_body_with_err ( & headers , body ) . and_then ( move | vec | { if code . is_success ( ) { info ! ( " " ) ; let res = serde_json :: from_slice :: < AssetData > ( & vec ) . map_err ( BerylliumError :: from ) ; future :: result ( res ) } else { let res = serde_json :: from_slice :: < SerdeValue > ( & vec ) . map_err ( BerylliumError :: from ) ; let msg = format ! ( " " res ) ; future :: err ( BerylliumError :: Other ( msg ) ) } } ) } ) ; Box :: new ( f ) }
Upload a given asset to Wire servers and return the asset key and token.
Upload a given asset to Wire servers and return the asset key and token .
&self
client
&HyperClient
req_data
T
asset_data
&[u8]
asset_type
ContentType