imgurs/src/cli/upload_image.rs

23 lines
561 B
Rust
Raw Normal View History

2022-01-23 12:05:32 +00:00
use super::print_image_info;
2022-01-22 21:02:51 +00:00
use imgurs::api::configuration::ImgurHandle;
use base64;
2022-01-23 12:05:32 +00:00
use log::error;
2022-01-22 21:14:26 +00:00
use std::fs;
use std::path::Path;
2022-01-22 21:02:51 +00:00
pub async fn upload_image(client: ImgurHandle, path: &str) {
2022-01-22 22:19:59 +00:00
let mut image: String = path.to_string();
2022-01-22 21:02:51 +00:00
if Path::new(path).exists() {
let bytes = fs::read(path).map_err(|err| err.to_string()).unwrap();
image = base64::encode(bytes);
}
match imgurs::api::upload_image::upload_image(client, &image).await {
Ok(i) => print_image_info(i, true),
Err(e) => error!("{e}")
2022-01-22 21:02:51 +00:00
}
}