bioscopelib/remote/
picture_remote.rsuse common::remote::services;
use std::fs::File;
use filepath::FilePath;
use std::io::Read;
use crate::jsonb::picture_data::PictureData;
use crate::dto::picture_response::PictureResponse;
pub fn create(
token: String,
picture: File,
picture_data: PictureData,
) -> Result<PictureResponse, String> {
let picture_data = serde_json::to_string(&picture_data).expect("Can't parse picture data");
let mut headers = hyper::header::HeaderMap::new();
headers.insert(
hyper::header::HeaderName::from_static("data"),
hyper::header::HeaderValue::from_str(picture_data.as_str()).expect("can't parse token"),
);
headers.insert(
hyper::header::HeaderName::from_static("Authorization"),
hyper::header::HeaderValue::from_str(token.as_str())
.expect("can't parse token"),
);
let mut buf: Vec<u8> = vec![];
let path = picture.path().map_err(|_| "Error".to_string())?;
File::open(path).unwrap().read_to_end(&mut buf).map_err(|_| "Error".to_string())?;
common::remote::post_bin(
Some(services::BIOSCOPE_API),
String::from("/picture"),
headers,
buf,
)
}