pub struct Minio { /* private fields */ }Expand description
Simple Storage Service (aka S3) client to perform bucket and object operations.
You do not have to wrap the Minio in an [Rc] or Arc to reuse it,
because it already uses an Arc internally.
§Create Minio client
use minio_rsc::{provider::StaticProvider,Minio};
let provider = StaticProvider::new("minio-access-key-test", "minio-secret-key-test", None);
let minio = Minio::builder()
.host("localhost:9022")
.provider(provider)
.secure(false)
.build()
.unwrap();
Implementations§
Source§impl Minio
impl Minio
Sourcepub fn builder() -> MinioBuilder
pub fn builder() -> MinioBuilder
get a minio MinioBuilder
pub fn region(&self) -> &str
pub async fn _execute<B: Into<Data<Error>>>( &self, method: Method, region: &str, bucket_name: Option<String>, object_name: Option<String>, data: B, headers: Option<HeaderMap>, query_params: Option<String>, ) -> Result<Response>
pub fn executor(&self, method: Method) -> BaseExecutor<'_>
Source§impl Minio
Operating multiUpload
impl Minio
Operating multiUpload
Sourcepub async fn abort_multipart_upload(
&self,
task: &MultipartUploadTask,
) -> Result<()>
pub async fn abort_multipart_upload( &self, task: &MultipartUploadTask, ) -> Result<()>
Aborts a multipart upload.
Sourcepub async fn complete_multipart_upload(
&self,
task: &MultipartUploadTask,
parts: Vec<Part>,
extra_header: Option<HeaderMap>,
) -> Result<CompleteMultipartUploadResult>
pub async fn complete_multipart_upload( &self, task: &MultipartUploadTask, parts: Vec<Part>, extra_header: Option<HeaderMap>, ) -> Result<CompleteMultipartUploadResult>
Completes a multipart upload by assembling previously uploaded parts.
pub async fn create_multipart_upload_with_versionid<B, K>( &self, bucket: B, key: K, version_id: String, ) -> Result<MultipartUploadTask>
Sourcepub async fn create_multipart_upload<B, K>(
&self,
bucket: B,
key: K,
) -> Result<MultipartUploadTask>
pub async fn create_multipart_upload<B, K>( &self, bucket: B, key: K, ) -> Result<MultipartUploadTask>
This action initiates a multipart upload and returns an MultipartUploadArgs.
Sourcepub async fn list_multipart_uploads(
&self,
args: ListMultipartUploadsArgs,
) -> Result<ListMultipartUploadsResult>
pub async fn list_multipart_uploads( &self, args: ListMultipartUploadsArgs, ) -> Result<ListMultipartUploadsResult>
lists in-progress multipart uploads.
Sourcepub async fn list_parts(
&self,
task: &MultipartUploadTask,
max_parts: Option<usize>,
part_number_marker: Option<usize>,
) -> Result<ListPartsResult>
pub async fn list_parts( &self, task: &MultipartUploadTask, max_parts: Option<usize>, part_number_marker: Option<usize>, ) -> Result<ListPartsResult>
Lists the parts that have been uploaded for a specific multipart upload.
Sourcepub async fn upload_part(
&self,
task: &MultipartUploadTask,
part_number: usize,
body: Bytes,
) -> Result<Part>
pub async fn upload_part( &self, task: &MultipartUploadTask, part_number: usize, body: Bytes, ) -> Result<Part>
Uploads a part in a multipart upload.
Sourcepub async fn upload_part_copy(
&self,
task: &MultipartUploadTask,
part_number: usize,
copy_source: CopySource,
) -> Result<Part>
pub async fn upload_part_copy( &self, task: &MultipartUploadTask, part_number: usize, copy_source: CopySource, ) -> Result<Part>
Uploads a part by copying data from an existing object as data source.
Source§impl Minio
Operating the bucket
impl Minio
Operating the bucket
Sourcepub async fn bucket_exists<B>(&self, bucket: B) -> Result<bool>where
B: Into<BucketArgs>,
pub async fn bucket_exists<B>(&self, bucket: B) -> Result<bool>where
B: Into<BucketArgs>,
Check if a bucket exists. If bucket exists and you have permission to access it, return [Ok(true)], otherwise [Ok(false)]
§Example
use minio_rsc::client::BucketArgs;
let exists:bool = minio.bucket_exists(BucketArgs::new("bucket")).await?;
let exists:bool = minio.bucket_exists("bucket").await?;Sourcepub async fn list_buckets(&self) -> Result<(Vec<Bucket>, Owner)>
pub async fn list_buckets(&self) -> Result<(Vec<Bucket>, Owner)>
List information of all accessible buckets.
§Example
let (buckets, owner) = minio.list_buckets().await.unwrap();Sourcepub async fn list_object_versions<B>(
&self,
bucket: B,
args: ListObjectVersionsArgs,
) -> Result<ListVersionsResult>where
B: Into<BucketArgs>,
pub async fn list_object_versions<B>(
&self,
bucket: B,
args: ListObjectVersionsArgs,
) -> Result<ListVersionsResult>where
B: Into<BucketArgs>,
Lists metadata about all versions of the objects in a bucket.
§Example
use minio_rsc::client::ListObjectVersionsArgs;
let mut args = ListObjectVersionsArgs::default();
args.max_keys = 100;
minio.list_object_versions("bucket", args).await;Sourcepub async fn list_objects<B>(
&self,
bucket: B,
args: ListObjectsArgs,
) -> Result<ListBucketResult>where
B: Into<BucketArgs>,
pub async fn list_objects<B>(
&self,
bucket: B,
args: ListObjectsArgs,
) -> Result<ListBucketResult>where
B: Into<BucketArgs>,
Lists object information of a bucket.
§Example
use minio_rsc::client::ListObjectsArgs;
let args = ListObjectsArgs::default().max_keys(10);
minio.list_objects("bucket", args).await;Sourcepub async fn get_bucket_acl<B>(&self, bucket: B) -> Result<AccessControlPolicy>where
B: Into<BucketArgs>,
pub async fn get_bucket_acl<B>(&self, bucket: B) -> Result<AccessControlPolicy>where
B: Into<BucketArgs>,
Sourcepub async fn get_bucket_region<B>(&self, bucket: B) -> Result<String>where
B: Into<BucketArgs>,
pub async fn get_bucket_region<B>(&self, bucket: B) -> Result<String>where
B: Into<BucketArgs>,
Get the Region the bucket resides in
Sourcepub async fn make_bucket<B>(
&self,
bucket: B,
object_lock: bool,
) -> Result<String>where
B: Into<BucketArgs>,
pub async fn make_bucket<B>(
&self,
bucket: B,
object_lock: bool,
) -> Result<String>where
B: Into<BucketArgs>,
Create a bucket with object_lock
§params
- object_lock: prevents objects from being deleted. Required to support retention and legal hold. Can only be enabled at bucket creation.
§Example
use minio_rsc::client::BucketArgs;
minio.make_bucket(BucketArgs::new("bucket"), true).await;
minio.make_bucket("bucket", false).await;Sourcepub async fn remove_bucket<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
pub async fn remove_bucket<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
Sourcepub async fn get_bucket_cors<B>(&self, bucket: B) -> Result<CORSConfiguration>where
B: Into<BucketArgs>,
pub async fn get_bucket_cors<B>(&self, bucket: B) -> Result<CORSConfiguration>where
B: Into<BucketArgs>,
Sourcepub async fn set_bucket_cors<B>(
&self,
bucket: B,
value: CORSConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
pub async fn set_bucket_cors<B>(
&self,
bucket: B,
value: CORSConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
Set CORSConfiguration of a bucket
Sourcepub async fn del_bucket_cors<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
pub async fn del_bucket_cors<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
Delete cors of a bucket
Sourcepub async fn get_bucket_encryption<B>(
&self,
bucket: B,
) -> Result<ServerSideEncryptionConfiguration>where
B: Into<BucketArgs>,
pub async fn get_bucket_encryption<B>(
&self,
bucket: B,
) -> Result<ServerSideEncryptionConfiguration>where
B: Into<BucketArgs>,
Get ServerSideEncryptionConfiguration of a bucket
§Example
let config = minio.get_bucket_encryption("bucket").await?;Sourcepub async fn set_bucket_encryption<B>(
&self,
bucket: B,
value: ServerSideEncryptionConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
pub async fn set_bucket_encryption<B>(
&self,
bucket: B,
value: ServerSideEncryptionConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
Set ServerSideEncryptionConfiguration of a bucket
Sourcepub async fn del_bucket_encryption<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
pub async fn del_bucket_encryption<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
Delete encryption of a bucket
Sourcepub async fn get_public_access_block<B>(
&self,
bucket: B,
) -> Result<PublicAccessBlockConfiguration>where
B: Into<BucketArgs>,
pub async fn get_public_access_block<B>(
&self,
bucket: B,
) -> Result<PublicAccessBlockConfiguration>where
B: Into<BucketArgs>,
Get PublicAccessBlockConfiguration of a bucket
§Example
let config = minio.get_public_access_block("bucket").await?;Sourcepub async fn set_public_access_block<B>(
&self,
bucket: B,
value: PublicAccessBlockConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
pub async fn set_public_access_block<B>(
&self,
bucket: B,
value: PublicAccessBlockConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
Set PublicAccessBlockConfiguration of a bucket
Sourcepub async fn del_public_access_block<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
pub async fn del_public_access_block<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
Delete publicAccessBlock of a bucket
Get Option<Tags> of a bucket. Note: return None if bucket had not set tagging or delete tagging.
§Example
use minio_rsc::client::BucketArgs;
use minio_rsc::client::Tags;
let tags:Option<Tags> = minio.get_bucket_tags(BucketArgs::new("bucket")).await?;
let tags:Option<Tags> = minio.get_bucket_tags("bucket").await?;Set Tags of a bucket
Delete tagging of a bucket
Sourcepub async fn get_bucket_versioning<B>(
&self,
bucket: B,
) -> Result<VersioningConfiguration>where
B: Into<BucketArgs>,
pub async fn get_bucket_versioning<B>(
&self,
bucket: B,
) -> Result<VersioningConfiguration>where
B: Into<BucketArgs>,
Get VersioningConfiguration of a bucket
§Example
let config = minio.get_bucket_versioning("bucket").await?;Sourcepub async fn set_bucket_versioning<B>(
&self,
bucket: B,
value: VersioningConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
pub async fn set_bucket_versioning<B>(
&self,
bucket: B,
value: VersioningConfiguration,
) -> Result<()>where
B: Into<BucketArgs>,
Set VersioningConfiguration of a bucket
Sourcepub async fn get_object_lock_config<B>(
&self,
bucket: B,
) -> Result<ObjectLockConfig>where
B: Into<BucketArgs>,
pub async fn get_object_lock_config<B>(
&self,
bucket: B,
) -> Result<ObjectLockConfig>where
B: Into<BucketArgs>,
Get ObjectLockConfig of a bucket
§Example
let config = minio.get_object_lock_config("bucket").await?;Sourcepub async fn set_object_lock_config<B>(
&self,
bucket: B,
value: ObjectLockConfig,
) -> Result<()>where
B: Into<BucketArgs>,
pub async fn set_object_lock_config<B>(
&self,
bucket: B,
value: ObjectLockConfig,
) -> Result<()>where
B: Into<BucketArgs>,
Set ObjectLockConfig of a bucket
Sourcepub async fn del_object_lock_config<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
pub async fn del_object_lock_config<B>(&self, bucket: B) -> Result<()>where
B: Into<BucketArgs>,
Delete ObjectLockConfig of a bucket.
§Example
use minio_rsc::client::BucketArgs;
minio.del_object_lock_config("bucket").await?;Source§impl Minio
Operating the object
impl Minio
Operating the object
Sourcepub async fn copy_object<B, K>(
&self,
bucket: B,
key: K,
src: CopySource,
) -> Result<()>
pub async fn copy_object<B, K>( &self, bucket: B, key: K, src: CopySource, ) -> Result<()>
Creates a copy of an object that is already stored in Minio.
§Exapmle
use minio_rsc::error::Result;
use minio_rsc::client::{CopySource, KeyArgs};
let src = CopySource::new("bucket","key1");
let response = minio.copy_object("bucket", "det", src).await?;
// modify content-type
let dst = KeyArgs::new("key2").content_type(Some("image/jpeg".to_string()));
let src = CopySource::new("bucket","key1").metadata_replace(true);
let response = minio.copy_object("bucket", dst, src).await?;Sourcepub async fn get_object<B, K>(&self, bucket: B, key: K) -> Result<Response>
pub async fn get_object<B, K>(&self, bucket: B, key: K) -> Result<Response>
Get reqwest::Response of an object.
§Exapmle
use reqwest::Response;
let response: Response = minio.get_object("bucket", "file.txt").await?;
let key = KeyArgs::new("file.txt").version_id(Some("cdabf31a-9752-4265-b137-6b3961fbaf9b".to_string()));
let response: Response = minio.get_object("bucket", key).await?;Sourcepub async fn get_object_torrent<B, K>(
&self,
bucket: B,
key: K,
) -> Result<Response>
pub async fn get_object_torrent<B, K>( &self, bucket: B, key: K, ) -> Result<Response>
Get torrent files from a bucket.
Sourcepub async fn put_object<B, K>(
&self,
bucket: B,
key: K,
data: Bytes,
) -> Result<()>
pub async fn put_object<B, K>( &self, bucket: B, key: K, data: Bytes, ) -> Result<()>
Uploads data to an object in a bucket.
§Exapmle
use reqwest::Response;
use std::collections::HashMap;
use minio_rsc::client::KeyArgs;
let data = "hello minio";
minio.put_object("bucket", "file.txt", data.into()).await?;
let metadata: HashMap<String, String> = [("filename".to_owned(), "file.txt".to_owned())].into();
let key = KeyArgs::new("file.txt")
.content_type(Some("text/plain".to_string()))
.metadata(metadata);
minio.put_object("bucket", key, data.into()).await?;Sourcepub async fn put_object_stream<B, K>(
&self,
bucket: B,
key: K,
stream: Pin<Box<dyn Stream<Item = Result<Bytes>> + Sync + Send>>,
len: Option<usize>,
) -> Result<()>
pub async fn put_object_stream<B, K>( &self, bucket: B, key: K, stream: Pin<Box<dyn Stream<Item = Result<Bytes>> + Sync + Send>>, len: Option<usize>, ) -> Result<()>
Upload large payload in an efficient manner easily.
- len: total byte length of stream.
If set None, the data will be transmitted through
multipart_upload. otherwise the data will be transmitted in multiple chunks through an HTTP request.
Sourcepub async fn remove_object<B, K>(&self, bucket: B, key: K) -> Result<()>
pub async fn remove_object<B, K>(&self, bucket: B, key: K) -> Result<()>
Sourcepub async fn stat_object<B, K>(
&self,
bucket: B,
key: K,
) -> Result<Option<ObjectStat>>
pub async fn stat_object<B, K>( &self, bucket: B, key: K, ) -> Result<Option<ObjectStat>>
Get object information.
return Ok(Some(ObjectStat)) if object exists and you have READ access to the object, otherwise return Ok(None)
§Exapmle
let object_stat = minio.stat_object("bucket", "file.txt").await?;Sourcepub async fn get_object_acl<B, K>(
&self,
bucket: B,
key: K,
) -> Result<AccessControlPolicy>
pub async fn get_object_acl<B, K>( &self, bucket: B, key: K, ) -> Result<AccessControlPolicy>
Get the access control list (ACL) of an object.
Sourcepub async fn is_object_legal_hold_enabled<B, K>(
&self,
bucket: B,
key: K,
) -> Result<bool>
pub async fn is_object_legal_hold_enabled<B, K>( &self, bucket: B, key: K, ) -> Result<bool>
Returns true if legal hold is enabled on an object.
Sourcepub async fn enable_object_legal_hold_enabled<B, K>(
&self,
bucket: B,
key: K,
) -> Result<()>
pub async fn enable_object_legal_hold_enabled<B, K>( &self, bucket: B, key: K, ) -> Result<()>
Enables legal hold on an object.
Sourcepub async fn disable_object_legal_hold_enabled<B, K>(
&self,
bucket: B,
key: K,
) -> Result<()>
pub async fn disable_object_legal_hold_enabled<B, K>( &self, bucket: B, key: K, ) -> Result<()>
Disables legal hold on an object.
Sourcepub async fn get_object_retention<B, K>(
&self,
bucket: B,
key: K,
) -> Result<Retention>
pub async fn get_object_retention<B, K>( &self, bucket: B, key: K, ) -> Result<Retention>
Get Retention of an object.
Sourcepub async fn set_object_retention<B, K>(
&self,
bucket: B,
key: K,
retention: Retention,
) -> Result<()>
pub async fn set_object_retention<B, K>( &self, bucket: B, key: K, retention: Retention, ) -> Result<()>
Set Retention of an object.
Sourcepub async fn select_object_content<B, K>(
&self,
bucket: B,
key: K,
request: SelectRequest,
) -> Result<SelectObjectReader>
pub async fn select_object_content<B, K>( &self, bucket: B, key: K, request: SelectRequest, ) -> Result<SelectObjectReader>
Filters the contents of an object based on a simple structured query language (SQL) statement.
§Example
use minio_rsc::datatype::{SelectRequest,InputSerialization,CsvInput,CompressionType,JsonOutput};
let input_serialization = InputSerialization::new(CsvInput::default(), CompressionType::NONE);
let output_serialization = JsonOutput::default().into();
let req = SelectRequest::new(
"Select * from s3object where s3object._1>100".to_owned(),
input_serialization,
output_serialization,
true,
None,
None);
let reader = client.select_object_content("bucket", "example.csv", req).await?;
let data = reader.read_all().await?;Source§impl Minio
Operating presigned
impl Minio
Operating presigned
Sourcepub async fn presigned_get_object(&self, args: PresignedArgs) -> Result<String>
pub async fn presigned_get_object(&self, args: PresignedArgs) -> Result<String>
Get presigned URL of an object to download its data with expiry time.
§Example
let presigned_get_object: String = minio
.presigned_get_object(
PresignedArgs::new("bucket", "file.txt")
.expires(24*3600)
.version_id("version_id"),
)
.await
.unwrap();Sourcepub async fn presigned_put_object(&self, args: PresignedArgs) -> Result<String>
pub async fn presigned_put_object(&self, args: PresignedArgs) -> Result<String>
Get presigned URL of an object to upload data with expiry time.
§Example
let presigned_put_object: String = minio
.presigned_put_object(
PresignedArgs::new("bucket", "file.txt")
.expires(24*3600)
.version_id("version_id"),
)
.await
.unwrap();