Crate minio_rsc

Crate minio_rsc 

Source
Expand description

§minio-rsc

Crates.io Documentation License

Rust Library for Minio. API is compliant with the Amazon S3 protocol.

§Minio client

use minio_rsc::client::{BucketArgs, KeyArgs};
use minio_rsc::error::Result;
use minio_rsc::provider::StaticProvider;
use minio_rsc::Minio;
use minio_rsc::client::PresignedArgs;

async fn example() -> Result<()> {
    let provider = StaticProvider::new("minio-access-key-test", "minio-secret-key-test", None);
    let minio = Minio::builder()
        .endpoint("localhost:9022")
        .provider(provider)
        .secure(false)
        .build()
        .unwrap();
    let (buckets, owner) = minio.list_buckets().await?;

    minio.make_bucket(BucketArgs::new("bucket1"), false).await?;
    minio.make_bucket("bucket2", true).await?;

    minio.put_object("bucket1", "hello.txt", "hello minio!".into()).await?;
    minio.stat_object("bucket1", "hello.txt").await?;
    minio.get_object("bucket1", "hello.txt").await?;
    let key = KeyArgs::new("hello.txt").version_id(Some("cdabf31a-9752-4265-b137-6b3961fbaf9b".to_string()));
    minio.get_object("bucket1", key).await?;
    minio.remove_object("bucket1", "hello.txt").await?;

    // if bucket feature enabled
    let bucket2 = minio.bucket("bucket2");
    bucket2.put_object("hello.txt", "hello minio!".into()).await?;
    bucket2.stat_object("hello.txt").await?;
    bucket2.get_object("hello.txt").await?;
    bucket2.remove_object("hello.txt").await?;

    // if fs-tokio feature enabled
    // download file to local
    minio.fget_object("bucket1", "hello.txt", "local.txt").await?;
    // upload file to minio
    minio.fput_object("bucket1", "hello.txt", "local.txt").await?;

    minio.remove_bucket("bucket1").await?;
    minio.remove_bucket("bucket2").await?;

    let presigned_get_object: String = minio
        .presigned_get_object(
            PresignedArgs::new("bucket", "file.txt")
                .expires(24*3600)
                .version_id("version_id"),
        )
        .await?;

    Ok(())
}

§Operations

§Features

  • fs-tokio which provides asynchronous local file operations based on the tokio. fput_object, fget_object
  • bucket Encapsulation of bucket operations.
  • ext Add extended operations that are experimental.

§Custom requests

Implemented by BaseExecutor

use minio_rsc::Minio;
use minio_rsc::http::Method;
use minio_rsc::errors::Result;
use reqwest::Response;
use bytes::Bytes;

async fn get_object(minio:Minio)-> Result<Response> {
    let executor = minio.executor(Method::GET);
    let res: Response = executor
        .bucket_name("bucket")
        .object_name("test.txt")
        .query("versionId", "cdabf31a-9752-4265-b137-6b3961fbaf9b")
        .send_ok()
        .await?;
    Ok(res)
}

async fn put_object(minio:Minio, data:Bytes)-> Result<()> {
    let executor = minio.executor(Method::PUT);
    let res: Response = executor
        .bucket_name("bucket")
        .object_name("test.txt")
        .body(data)
        .send_ok()
        .await?;
    Ok(())
}

Re-exports§

pub use crate::client::Minio;
pub use http;

Modules§

client
Minio client
datatype
Data types
error
Error and Result module.
provider
Credential provider
sse
Server-side encryption
time
Time formatter for S3 APIs.
xml
Serde XML for data types.

Structs§

Credentials
Represents credentials access key, secret key and session token.

Enums§

Data
Payload for http request

Functions§

presign_v4
Do signature V4 of given presign request. Returned uri:Strig
sign_request_v4
Do signature V4 of given request params, add the headers required by S3 and convert Data to Body.
sign_v4_authorization
Do signature V4 of given request for given service name