Add new put and get APIs for objects (#78)

- put_object_content -> streaming object uploads

- put_object_from_file -> upload file

- put_object, create_multipart_uload, abort_multipart_upload,
upload_part, complete_multipart_upload -> S3 APIs for single and
multipart uploads

- get_object -> streaming object downloads
This commit is contained in:
Aditya Manthramurthy
2024-04-02 18:09:54 -07:00
committed by GitHub
parent 3f160cb6c0
commit 54b671ef4c
19 changed files with 2053 additions and 107 deletions

View File

@@ -1,6 +1,6 @@
use log::{error, info};
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs, UploadObjectArgs};
use minio::s3::client::Client;
use log::info;
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs};
use minio::s3::client::ClientBuilder;
use minio::s3::creds::StaticProvider;
use minio::s3::http::BaseUrl;
use std::path::Path;
@@ -9,8 +9,7 @@ use std::path::Path;
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
//let base_url = "https://play.min.io".parse::<BaseUrl>()?;
let base_url: BaseUrl = "http://192.168.178.227:9000".parse::<BaseUrl>()?;
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
info!("Trying to connect to MinIO at: `{:?}`", base_url);
@@ -20,13 +19,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
None,
);
let client = Client::new(
base_url.clone(),
Some(Box::new(static_provider)),
None,
None,
)
.unwrap();
let client = ClientBuilder::new(base_url.clone())
.provider(Some(Box::new(static_provider)))
.build()?;
let bucket_name: &str = "asiatrip";
@@ -45,28 +40,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
}
// File we are going to upload to the bucket
let filename: &Path = Path::new("/home/user/Photos/asiaphotos.zip");
let filename: &Path = Path::new("/tmp/asiaphotos.zip");
// Name of the object that will be stored in the bucket
let object_name: &str = "asiaphotos-2015.zip";
info!("filename {}", &filename.to_str().unwrap());
// Check if the file exists
let file_exists: bool = filename.exists();
if !file_exists {
error!("File `{}` does not exist!", filename.display());
()
}
// Upload 'filename' as 'object_name' to bucket 'bucket_name'.
client
.upload_object(
&mut UploadObjectArgs::new(&bucket_name, &object_name, &filename.to_str().unwrap())
.unwrap(),
)
.await
.unwrap();
.put_object_from_file(bucket_name, object_name, filename)
.send()
.await?;
info!(
"file `{}` is successfully uploaded as object `{object_name}` to bucket `{bucket_name}`.",