mod common;
use crate::common::{create_bucket_if_not_exists, create_client};
use minio::s3::MinioClient;
use minio::s3::builders::ObjectContent;
use minio::s3::types::ObjectKey;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init(); let client: MinioClient = create_client()?;
let bucket: &str = "file-upload-rust-bucket";
create_bucket_if_not_exists(bucket, &client).await?;
let filename: &Path = Path::new("./examples/cat.png");
let object: &str = "cat.png";
if filename.exists() {
log::info!("File '{}' exists.", &filename.to_str().unwrap());
} else {
log::error!("File '{}' does not exist.", &filename.to_str().unwrap());
return Ok(());
}
let content = ObjectContent::from(filename);
client
.put_object_content(bucket, ObjectKey::new(object)?, content)?
.build()
.send()
.await?;
log::info!(
"file '{}' is successfully uploaded as object '{object}' to bucket '{bucket}'.",
filename.display()
);
Ok(())
}