Minio

Struct Minio 

Source
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

Source

pub fn builder() -> MinioBuilder

get a minio MinioBuilder

Source

pub fn region(&self) -> &str

Source

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>

Source

pub fn executor(&self, method: Method) -> BaseExecutor<'_>

Source

pub fn bucket<B>(&self, bucket: B) -> Bucket
where B: Into<BucketArgs>,

Instantiate an Bucket

Source§

impl Minio

Operating multiUpload

Source

pub async fn abort_multipart_upload( &self, task: &MultipartUploadTask, ) -> Result<()>

Aborts a multipart upload.

Source

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.

Source

pub async fn create_multipart_upload_with_versionid<B, K>( &self, bucket: B, key: K, version_id: String, ) -> Result<MultipartUploadTask>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Source

pub async fn create_multipart_upload<B, K>( &self, bucket: B, key: K, ) -> Result<MultipartUploadTask>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

This action initiates a multipart upload and returns an MultipartUploadArgs.

Source

pub async fn list_multipart_uploads( &self, args: ListMultipartUploadsArgs, ) -> Result<ListMultipartUploadsResult>

lists in-progress multipart uploads.

Source

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.

Source

pub async fn upload_part( &self, task: &MultipartUploadTask, part_number: usize, body: Bytes, ) -> Result<Part>

Uploads a part in a multipart upload.

Source

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

Source

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?;
Source

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();
Source

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;
Source

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;
Source

pub async fn get_bucket_acl<B>(&self, bucket: B) -> Result<AccessControlPolicy>
where B: Into<BucketArgs>,

Get AccessControlPolicy of a bucket

§Example
let config = minio.get_bucket_acl("bucket").await?;
Source

pub async fn get_bucket_region<B>(&self, bucket: B) -> Result<String>
where B: Into<BucketArgs>,

Get the Region the bucket resides in

Source

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;
Source

pub async fn remove_bucket<B>(&self, bucket: B) -> Result<()>
where B: Into<BucketArgs>,

Remove an empty bucket. If the operation succeeds, return Ok otherwise Error

§Example
use minio_rsc::client::BucketArgs;
minio.remove_bucket(BucketArgs::new("bucket")).await;
minio.remove_bucket("bucket").await;
Source

pub async fn get_bucket_cors<B>(&self, bucket: B) -> Result<CORSConfiguration>
where B: Into<BucketArgs>,

Get CORSConfiguration of a bucket

§Example
let config = minio.get_bucket_cors("bucket").await?;
Source

pub async fn set_bucket_cors<B>( &self, bucket: B, value: CORSConfiguration, ) -> Result<()>
where B: Into<BucketArgs>,

Set CORSConfiguration of a bucket

Source

pub async fn del_bucket_cors<B>(&self, bucket: B) -> Result<()>
where B: Into<BucketArgs>,

Delete cors of a bucket

Source

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?;
Source

pub async fn set_bucket_encryption<B>( &self, bucket: B, value: ServerSideEncryptionConfiguration, ) -> Result<()>
where B: Into<BucketArgs>,

Source

pub async fn del_bucket_encryption<B>(&self, bucket: B) -> Result<()>
where B: Into<BucketArgs>,

Delete encryption of a bucket

Source

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?;
Source

pub async fn set_public_access_block<B>( &self, bucket: B, value: PublicAccessBlockConfiguration, ) -> Result<()>
where B: Into<BucketArgs>,

Source

pub async fn del_public_access_block<B>(&self, bucket: B) -> Result<()>
where B: Into<BucketArgs>,

Delete publicAccessBlock of a bucket

Source

pub async fn get_bucket_tags<B>(&self, bucket: B) -> Result<Option<Tags>>
where B: Into<BucketArgs>,

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?;
Source

pub async fn set_bucket_tags<B>(&self, bucket: B, value: Tags) -> Result<()>
where B: Into<BucketArgs>,

Set Tags of a bucket

Source

pub async fn del_bucket_tags<B>(&self, bucket: B) -> Result<()>
where B: Into<BucketArgs>,

Delete tagging of a bucket

Source

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?;
Source

pub async fn set_bucket_versioning<B>( &self, bucket: B, value: VersioningConfiguration, ) -> Result<()>
where B: Into<BucketArgs>,

Set VersioningConfiguration of a bucket

Source

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?;
Source

pub async fn set_object_lock_config<B>( &self, bucket: B, value: ObjectLockConfig, ) -> Result<()>
where B: Into<BucketArgs>,

Set ObjectLockConfig of a bucket

Source

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

Source

pub async fn copy_object<B, K>( &self, bucket: B, key: K, src: CopySource, ) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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?;
Source

pub async fn get_object<B, K>(&self, bucket: B, key: K) -> Result<Response>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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?;
Source

pub async fn get_object_torrent<B, K>( &self, bucket: B, key: K, ) -> Result<Response>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Get torrent files from a bucket.

Source

pub async fn put_object<B, K>( &self, bucket: B, key: K, data: Bytes, ) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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?;
Source

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<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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.
Source

pub async fn remove_object<B, K>(&self, bucket: B, key: K) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Remove an object.

§Exapmle
let response = minio.remove_object("bucket", "file.txt").await?;
Source

pub async fn stat_object<B, K>( &self, bucket: B, key: K, ) -> Result<Option<ObjectStat>>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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?;
Source

pub async fn get_object_acl<B, K>( &self, bucket: B, key: K, ) -> Result<AccessControlPolicy>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Get the access control list (ACL) of an object.

Returns true if legal hold is enabled on an object.

Enables legal hold on an object.

Disables legal hold on an object.

Source

pub async fn get_object_tags<B, K>(&self, bucket: B, key: K) -> Result<Tags>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Get Tags of an object.

§Example
use minio_rsc::client::Tags;

let tags: Tags = minio.get_object_tags("bucket", "file.txt").await?;
Source

pub async fn set_object_tags<B, K, T>( &self, bucket: B, key: K, tags: T, ) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>, T: Into<Tags>,

Set Tags of an object.

§Example
use minio_rsc::client::Tags;

let mut tags: Tags = Tags::new();
tags.insert("key1", "value1")
    .insert("key2", "value2");
minio.set_object_tags("bucket", "file.txt", tags).await?;
Source

pub async fn del_object_tags<B, K>(&self, bucket: B, key: K) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Delete tags of an object.

§Example
minio.del_object_tags("bucket", "file.txt").await?;
Source

pub async fn get_object_retention<B, K>( &self, bucket: B, key: K, ) -> Result<Retention>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Get Retention of an object.

Source

pub async fn set_object_retention<B, K>( &self, bucket: B, key: K, retention: Retention, ) -> Result<()>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

Set Retention of an object.

Source

pub async fn select_object_content<B, K>( &self, bucket: B, key: K, request: SelectRequest, ) -> Result<SelectObjectReader>
where B: Into<BucketArgs>, K: Into<KeyArgs>,

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

Source

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();
Source

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();

Trait Implementations§

Source§

impl Clone for Minio

Source§

fn clone(&self) -> Minio

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Minio

§

impl !RefUnwindSafe for Minio

§

impl Send for Minio

§

impl Sync for Minio

§

impl Unpin for Minio

§

impl !UnwindSafe for Minio

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,