IMinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io")
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.WithSSL()
.Build();
AWS S3
IIMinioClient minioClient = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
.WithSSL()
.Build();
public MinioClient(string endpoint, string accessKey = "", string secretKey = "", string region = "", string sessionToken="")
Creates MinIO client object with given endpoint.AccessKey, secretKey, region and sessionToken are optional parameters, and can be omitted for anonymous access.
The client object uses Http access by default. To use Https, chain method WithSSL() to client object to use secure transfer protocol
Parameters
Param
Description
endpoint
string
endPoint is an URL, domain name, IPv4 address or IPv6 address.Valid endpoints are listed below:
s3.amazonaws.com
play.min.io
localhost
play.min.io
accessKey
string
accessKey is like user-id that uniquely identifies your account.This field is optional and can be omitted for anonymous access.
secretKey
string
secretKey is the password to your account.This field is optional and can be omitted for anonymous access.
region
string
region to which calls should be made.This field is optional and can be omitted.
sessionToken
string
sessionToken needs to be set if temporary access credentials are used
public MinioClient()
Creates MinIO client. This client gives an empty object that can be used with Chaining to populate only the member variables we need.
The next important step is to connect to an endpoint. You can chain one of the overloaded method WithEndpoint() to client object to connect.
This client object also uses Http access by default. To use Https, chain method WithSSL() or WithSSL(true) to client object to use secure transfer protocol.
To use non-anonymous access, chain method WithCredentials() to the client object along with the access key & secret key.
Finally chain the method Build() to get the finally built client object.
// 1. Using Builder with public MinioClient(), Endpoint, Credentials & Secure (HTTPS) connection
IMinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io")
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.WithSSL()
.Build()
// 2. Using Builder with public MinioClient(), Endpoint, Credentials & Secure (HTTPS) connection
IMinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io", 9000, true)
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.WithSSL()
.Build()
// 3. Initializing minio client with proxy
IWebProxy proxy = new WebProxy("192.168.0.1", 8000);
IMinioClient minioClient = new MinioClient()
.WithEndpoint("my-ip-address:9000")
.WithCredentials("minio", "minio123")
.WithSSL()
.WithProxy(proxy)
.Build();
// 1. Using Builder with public MinioClient(), Endpoint, Credentials, Secure (HTTPS) connection & proxy
IMinioClient s3Client = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("YOUR-AWS-ACCESSKEYID", "YOUR-AWS-SECRETACCESSKEY")
.WithSSL()
.WithProxy(proxy)
.Build();
Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken))
Creates a new bucket.
Parameters
Param
Description
bucketName
string
Name of the bucket
region
string
Optional parameter. Defaults to us-east-1 for AWS requests
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Create bucket if it doesn't exist.
bool found = await minioClient.BucketExistsAsync("mybucket");
if (found)
Console.WriteLine("mybucket already exists");
// Create bucket 'my-bucketname'.
await minioClient.MakeBucketAsync("mybucket");
Console.WriteLine("mybucket is created successfully");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task MakeBucketAsync(MakeBucketArgs args, CancellationToken cancellationToken = default(CancellationToken))
Creates a new bucket.
Parameters
Param
Description
MakeBucketArgs
Arguments Object - name, location.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Create bucket if it doesn't exist.
bool found = await minioClient.BucketExistsAsync(bktExistArgs);
if (found)
Console.WriteLine(bktExistArgs.BucketName +" already exists");
// Create bucket 'my-bucketname'.
await minioClient.MakeBucketAsync(mkBktArgs);
Console.WriteLine(mkBktArgs.BucketName + " is created successfully");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<ListAllMyBucketsResult> ListBucketsAsync(CancellationToken cancellationToken = default(CancellationToken))
Lists all buckets.
Param
Description
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// List buckets that have read access.
var list = await minioClient.ListBucketsAsync();
foreach (Bucket bucket in list.Buckets)
Console.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<bool> BucketExistsAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
Checks if a bucket exists.
Parameters
Param
Description
bucketName
string
Name of the bucket.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check whether 'my-bucketname' exists or not.
bool found = await minioClient.BucketExistsAsync(bucketName);
Console.WriteLine("bucket-name " + ((found == true) ? "exists" : "does not exist"));
catch (MinioException e)
Console.WriteLine("[Bucket] Exception: {0}", e);
Task<bool> BucketExistsAsync(BucketExistsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Checks if a bucket exists.
Parameters
Param
Description
BucketExistsArgs
Argument object - bucket name.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check whether 'my-bucketname' exists or not.
bool found = await minioClient.BucketExistsAsync(args);
Console.WriteLine(args.BucketName + " " + ((found == true) ? "exists" : "does not exist"));
catch (MinioException e)
Console.WriteLine("[Bucket] Exception: {0}", e);
Task RemoveBucketAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
Removes a bucket.
NOTE: - removeBucket does not delete the objects inside the bucket. The objects need to be deleted using the removeObject API.
Parameters
Param
Description
bucketName
string
Name of the bucket
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check if my-bucket exists before removing it.
bool found = await minioClient.BucketExistsAsync("mybucket");
if (found)
// Remove bucket my-bucketname. This operation will succeed only if the bucket is empty.
await minioClient.RemoveBucketAsync("mybucket");
Console.WriteLine("mybucket is removed successfully");
Console.WriteLine("mybucket does not exist");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveBucketAsync(RemoveBucketArgs args, CancellationToken cancellationToken = default(CancellationToken))
Removes a bucket.
NOTE: - removeBucket does not delete the objects inside the bucket. The objects need to be deleted using the removeObject API.
Parameters
Param
Description
RemoveBucketArgs
Arguments Object - bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check if my-bucket exists before removing it.
bool found = await minioClient.BucketExistsAsync(bktExistsArgs);
if (found)
// Remove bucket my-bucketname. This operation will succeed only if the bucket is empty.
await minioClient.RemoveBucketAsync(rmBktArgs);
Console.WriteLine(rmBktArgs.BucketName + " is removed successfully");
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<VersioningConfiguration> GetVersioningAsync(GetVersioningArgs args, CancellationToken cancellationToken = default(CancellationToken))
Get versioning information for a bucket.
Parameters
Param
Description
GetVersioningArgs
Arguments Object - bucket name.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
VersioningConfiguration
:VersioningConfiguration with information populated from response.
Example
// Check whether 'mybucket' exists or not.
bool found = minioClient.BucketExistsAsync(bktExistsArgs);
if (found)
var args = new GetVersioningArgs("mybucket")
.WithSSL();
VersioningConfiguration vc = await minio.GetVersioningInfoAsync(args);
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetVersioningAsync(SetVersioningArgs args, CancellationToken cancellationToken = default(CancellationToken))
Set versioning to Enabled or Suspended for a bucket.
Parameters
Param
Description
SetVersioningArgs
Arguments Object - bucket name, versioning status.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check whether 'mybucket' exists or not.
bool found = minioClient.BucketExistsAsync(bktExistsArgs);
if (found)
var args = new SetVersioningArgs("mybucket")
.WithSSL()
.WithVersioningEnabled();
await minio.SetVersioningAsync(setArgs);
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetBucketEncryptionAsync(SetBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken));
Sets the Bucket Encryption Configuration of a bucket.
Parameters
Param
Description
SetBucketEncryptionArgs
SetBucketEncryptionArgs Argument Object with bucket, encryption configuration
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Set Encryption Configuration for the bucket
SetBucketEncryptionArgs args = new SetBucketEncryptionArgs()
.WithBucket(bucketName)
.WithEncryptionConfig(config);
await minio.SetBucketEncryptionAsync(args);
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<ServerSideEncryptionConfiguration> GetBucketEncryptionAsync(GetBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))
Gets the Bucket Encryption configuration of the bucket.
Parameters
Param
Description
GetBucketEncryptionArgs
GetBucketEncryptionArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
ServerSideEncryptionConfiguration object which contains the bucket encryption configuration.
Example
// Get Bucket Encryption Configuration for the bucket
var args = new GetBucketEncryptionArgs()
.WithBucket(bucketName);
ServerSideEncryptionConfiguration config = await minio.GetBucketEncryptionAsync(args);
Console.WriteLine($"Got encryption configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveBucketEncryptionAsync(RemoveBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))
Remove the Bucket Encryption configuration of an object.
Parameters
Param
Description
RemoveBucketEncryptionArgs
RemoveBucketEncryptionArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Remove Bucket Encryption Configuration for the bucket
var args = new RemoveBucketEncryptionArgs()
.WithBucket(bucketName);
await minio.RemoveBucketEncryptionAsync(args);
Console.WriteLine($"Removed encryption configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetBucketTagsAsync(SetBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Sets tags to a bucket.
Parameters
Param
Description
SetBucketTagsArgs
SetBucketTagsArgs Argument Object with bucket, tags to set
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Set Tags for the bucket
SetBucketTagsArgs args = new SetBucketTagsArgs()
.WithBucket(bucketName)
.WithTagging(tags);
await minio.SetBucketTagsAsync(args);
Console.WriteLine($"Set Tags for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<Tagging> GetBucketTagsAsync(GetBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Gets tags of a bucket.
Parameters
Param
Description
GetBucketTagsArgs
GetBucketTagsArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Get Bucket Tags for the bucket
var args = new GetBucketTagsArgs()
.WithBucket(bucketName);
var tags = await minio.GetBucketTagsAsync(args);
Console.WriteLine($"Got tags for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveBucketTagsAsync(RemoveBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Deletes tags of a bucket.
Parameters
Param
Description
RemoveBucketTagsArgs
RemoveBucketTagsArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Remove Bucket Encryption Configuration for the bucket
var args = new RemoveBucketTagsArgs()
.WithBucket(bucketName);
await minio.RemoveBucketTagsAsync(args);
Console.WriteLine($"Removed tags for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetBucketLifecycleAsync(SetBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
Sets Lifecycle configuration to a bucket.
Parameters
Param
Description
SetBucketLifecycleArgs
SetBucketLifecycleArgs Argument Object with bucket name, Lifecycle configuration to set
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Set Lifecycle configuration for the bucket
SetBucketLifecycleArgs args = new SetBucketLifecycleArgs()
.WithBucket(bucketName)
.WithConfiguration(lfc);
await minio.SetBucketLifecycleAsync(args);
Console.WriteLine($"Set Lifecycle for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<LifecycleConfiguration> GetBucketLifecycleAsync(GetBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
Gets Lifecycle configuration of a bucket.
Parameters
Param
Description
GetBucketLifecycleArgs
GetBucketLifecycleArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task<LifecycleConfiguration>
: LifecycleConfiguration object which contains the Lifecycle configuration details.
Listed Exceptions:
AuthorizationException
: upon access or secret key wrong or not found
InvalidBucketNameException
: upon invalid bucket name
BucketNotFoundException
: upon bucket with name not found
MalFormedXMLException
: upon configuration XML in http request validation failure
UnexpectedMinioException
: upon internal errors encountered during the operation
Example
// Get Bucket Lifecycle configuration for the bucket
var args = new GetBucketLifecycleArgs()
.WithBucket(bucketName);
var lfc = await minio.GetBucketLifecycleAsync(args);
Console.WriteLine($"Got Lifecycle configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveBucketLifecycleAsync(RemoveBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
Deletes Lifecycle configuration of a bucket.
Parameters
Param
Description
RemoveBucketLifecycleArgs
RemoveBucketLifecycleArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Remove Bucket Lifecycle Configuration for the bucket
var args = new RemoveBucketLifecycleArgs()
.WithBucket(bucketName);
await minio.RemoveBucketLifecycleAsync(args);
Console.WriteLine($"Removed Lifecycle configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetBucketReplicationAsync(SetBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Sets Replication configuration to a bucket.
Parameters
Param
Description
SetBucketReplicationArgs
SetBucketReplicationArgs Argument Object with bucket name, Replication configuration to set
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Set Replication configuration for the bucket
SetBucketReplicationArgs args = new SetBucketReplicationArgs()
.WithBucket(bucketName)
.WithConfiguration(cfg);
await minio.SetBucketReplicationAsync(args);
Console.WriteLine($"Set Replication configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<ReplicationConfiguration> GetBucketReplicationAsync(GetBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Gets Replication configuration of a bucket.
Parameters
Param
Description
GetBucketReplicationArgs
GetBucketReplicationArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task<ReplicationConfiguration>
: ReplicationConfiguration object which contains the Replication configuration details.
Listed Exceptions:
AuthorizationException
: upon access or secret key wrong or not found
InvalidBucketNameException
: upon invalid bucket name
BucketNotFoundException
: upon bucket with name not found
MalFormedXMLException
: upon configuration XML in http request validation failure
UnexpectedMinioException
: upon internal errors encountered during the operation
Example
// Get Bucket Replication for the bucket
var args = new GetBucketReplicationArgs()
.WithBucket(bucketName);
var cfg = await minio.GetBucketReplicationAsync(args);
Console.WriteLine($"Got Replication configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveBucketReplicationAsync(RemoveBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Deletes Replication configuration of a bucket.
Parameters
Param
Description
RemoveBucketReplicationArgs
RemoveBucketReplicationArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Remove Bucket Replication Configuration for the bucket
var args = new RemoveBucketReplicationArgs()
.WithBucket(bucketName);
await minio.RemoveBucketReplicationAsync(args);
Console.WriteLine($"Removed Replication configuration for bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
IObservable<Item> ListObjectsAsync(ListObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
Lists all objects (with version IDs, if existing) in a bucket.
Parameters
Param
Description
ListObjectArgs
ListObjectArgs object - encapsulates bucket name, prefix, show recursively, show versions.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Just list of objects
// Check whether 'mybucket' exists or not.
bool found = minioClient.BucketExistsAsync("mybucket");
if (found)
// List objects from 'my-bucketname'
ListObjectArgs args = new ListObjectArgs()
.WithBucket("mybucket")
.WithPrefix("prefix")
.WithRecursive(true);
IObservable<Item> observable = minioClient.ListObjectsAsync(args);
IDisposable subscription = observable.Subscribe(
item => Console.WriteLine("OnNext: {0}", item.Key),
ex => Console.WriteLine("OnError: {0}", ex.Message),
() => Console.WriteLine("OnComplete: {0}"));
Console.WriteLine("mybucket does not exist");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
// List of objects with version IDs.
// Check whether 'mybucket' exists or not.
bool found = minioClient.BucketExistsAsync("mybucket");
if (found)
// List objects from 'my-bucketname'
ListObjectArgs args = new ListObjectArgs()
.WithBucket("mybucket")
.WithPrefix("prefix")
.WithRecursive(true)
.WithVersions(true)
IObservable<Item> observable = minioClient.ListObjectsAsync(args, true);
IDisposable subscription = observable.Subscribe(
item => Console.WriteLine("OnNext: {0} - {1}", item.Key, item.VersionId),
ex => Console.WriteLine("OnError: {0}", ex.Message),
() => Console.WriteLine("OnComplete: {0}"));
Console.WriteLine("mybucket does not exist");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetObjectLockConfigurationAsync(SetObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Sets object-lock configuration in a bucket.
Parameters
Param
Description
SetObjectLockConfigurationArgs
SetObjectLockConfigurationArgs Argument Object with bucket, lock configuration to set
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
ObjectLockConfiguration config = = new ObjectLockConfiguration(RetentionMode.GOVERNANCE, 35);
// Set Object Lock Configuration for the bucket
SetObjectLockConfigurationArgs args = new SetObjectLockConfigurationArgs()
.WithBucket(bucketName)
.WithLockConfiguration(config);
await minio.SetObjectLockConfigurationAsync(args);
Console.WriteLine($"Set Object lock configuration to bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<ObjectLockConfiguration> GetObjectLockConfigurationAsync(GetObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Gets object-lock configuration of a bucket.
Parameters
Param
Description
GetObjectLockConfigurationArgs
GetObjectLockConfigurationArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task<ObjectLockConfiguration>
: ObjectLockConfiguration object which containing lock-enabled status & Object lock rule.
Listed Exceptions:
AuthorizationException
: upon access or secret key wrong or not found
InvalidBucketNameException
: upon invalid bucket name
BucketNotFoundException
: upon bucket with name not found
MalFormedXMLException
: upon configuration XML in http request validation failure
UnexpectedMinioException
: upon internal errors encountered during the operation
Example
// Get the Object Lock Configuration for the bucket
var args = new GetObjectLockConfigurationArgs()
.WithBucket(bucketName);
var config = await minio.GetObjectLockConfigurationAsync(args);
Console.WriteLine($"Object lock configuration on bucket {bucketName} is : " + config.ObjectLockEnabled);
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveObjectLockConfigurationAsync(RemoveObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
Removes object-lock configuration on a bucket.
Parameters
Param
Description
RemoveObjectLockConfigurationArgs
RemoveObjectLockConfigurationArgs Argument Object with bucket name
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Remove Object Lock Configuration on the bucket
var args = new RemoveObjectLockConfigurationArgs()
.WithBucket(bucketName);
await minio.RemoveObjectLockConfigurationAsync(args);
Console.WriteLine($"Removed Object lock configuration on bucket {bucketName}.");
catch(MinioException e)
Console.WriteLine("Error occurred: " + e);
IObservable<Upload> ListIncompleteUploads(ListIncompleteUploadsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Lists partially uploaded objects in a bucket.
Parameters
Param
Description
ListIncompleteUploadsArgs
ListIncompleteUploadsArgs object - encapsulates bucket name, prefix, show recursively.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
// Check whether 'mybucket' exist or not.
bool found = minioClient.BucketExistsAsync("mybucket");
if (found)
// List all incomplete multipart upload of objects in 'mybucket'
ListIncompleteUploadsArgs listArgs = new ListIncompleteUploadsArgs()
.WithBucket("mybucket")
.WithPrefix("prefix")
.WithRecursive(true);
IObservable<Upload> observable = minioClient.ListIncompleteUploads(listArgs);
IDisposable subscription = observable.Subscribe(
item => Console.WriteLine("OnNext: {0}", item.Key),
ex => Console.WriteLine("OnError: {0}", ex.Message),
() => Console.WriteLine("OnComplete: {0}"));
Console.WriteLine("mybucket does not exist");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
IObservable<MinioNotificationRaw> ListenBucketNotificationsAsync(ListenBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Subscribes to bucket change notifications (a Minio-only extension)
Parameters
Param
Description
ListenBucketNotificationsArgs
ListenBucketNotificationsArgs object - encapsulates bucket name, list of events, prefix, suffix.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
IObservable<MinioNotificationRaw>
: an Observable of MinioNotificationRaw, which contain the raw JSON notifications. Use the MinioNotification class to deserialise using the JSON library of your choice.
Example
var events = new List<EventType> { EventType.ObjectCreatedAll };
var prefix = null;
var suffix = null;
ListenBucketNotificationsArgs args = new ListenBucketNotificationsArgs()
.WithBucket(bucketName)
.WithEvents(events)
.WithPrefix(prefix)
.WithSuffix(suffix);
IObservable<MinioNotificationRaw> observable = minioClient.ListenBucketNotificationsAsync(args);
IDisposable subscription = observable.Subscribe(
notification => Console.WriteLine($"Notification: {notification.json}"),
ex => Console.WriteLine($"OnError: {ex}"),
() => Console.WriteLine($"Stopped listening for bucket notifications\n"));
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<String> GetPolicyAsync(GetPolicyArgs args, CancellationToken cancellationToken = default(CancellationToken))
Get bucket policy.
Parameters
Param
Description
GetPolicyArgs
GetPolicyArgs object encapsulating bucket name.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task<String>
: The current bucket policy for given bucket as a json string.
Listed Exceptions:
InvalidBucketNameException
: upon invalid bucket name.
InvalidObjectPrefixException
: upon invalid object prefix.
ConnectionException
: upon connection error.
AccessDeniedException
: upon access denial
InternalClientException
: upon internal library error.
BucketNotFoundException
: upon missing bucket
Example
GetPolicyArgs args = new GetPolicyArgs()
.WithBucket("myBucket");
String policyJson = await minioClient.GetPolicyAsync(args);
Console.WriteLine("Current policy: " + policyJson);
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task SetPolicyAsync(SetPolicyArgs args, CancellationToken cancellationToken = default(CancellationToken))
Set policy on bucket.
Parameters
Param
Description
SetPolicyArgs
SetPolicyArgs object encapsulating bucket name, Policy as a json string.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
string policyJson = $@"{{""Version"":""2012-10-17"",""Statement"":[{{""Action"":[""s3:GetBucketLocation""],""Effect"":""Allow"",""Principal"":{{""AWS"":[""*""]}},""Resource"":[""arn:aws:s3:::{bucketName}""],""Sid"":""""}},{{""Action"":[""s3:ListBucket""],""Condition"":{{""StringEquals"":{{""s3:prefix"":[""foo"",""prefix/""]}}}},""Effect"":""Allow"",""Principal"":{{""AWS"":[""*""]}},""Resource"":[""arn:aws:s3:::{bucketName}""],""Sid"":""""}},{{""Action"":[""s3:GetObject""],""Effect"":""Allow"",""Principal"":{{""AWS"":[""*""]}},""Resource"":[""arn:aws:s3:::{bucketName}/foo*"",""arn:aws:s3:::{bucketName}/prefix/*""],""Sid"":""""}}]}}";
SetPolicyArgs args = new SetPolicyArgs()
.WithBucket("myBucket")
.WithPolicy(policyJson);
await minioClient.SetPolicyAsync(args);
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
SetBucketNotificationAsync(SetBucketNotificationsArgs args)
Task SetBucketNotificationAsync(SetBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Sets notification configuration for a given bucket
Parameters
Param
Description
SetBucketNotificationsArgs
SetBucketNotificationsArgs object encapsulating bucket name, notification configuration object.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
BucketNotification notification = new BucketNotification();
Arn topicArn = new Arn("aws", "sns", "us-west-1", "412334153608", "topicminio");
TopicConfig topicConfiguration = new TopicConfig(topicArn);
List<EventType> events = new List<EventType>(){ EventType.ObjectCreatedPut , EventType.ObjectCreatedCopy };
topicConfiguration.AddEvents(events);
topicConfiguration.AddFilterPrefix("images");
topicConfiguration.AddFilterSuffix("jpg");
notification.AddTopic(topicConfiguration);
QueueConfig queueConfiguration = new QueueConfig("arn:aws:sqs:us-west-1:482314153608:testminioqueue1");
queueConfiguration.AddEvents(new List<EventType>() { EventType.ObjectCreatedCompleteMultipartUpload });
notification.AddQueue(queueConfiguration);
SetBucketNotificationsArgs args = new SetBucketNotificationsArgs()
.WithBucket(bucketName)
.WithBucketNotificationConfiguration(notification);
await minio.SetBucketNotificationsAsync(args);
Console.WriteLine("Notifications set for the bucket " + args.BucketName + " successfully");
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task<BucketNotification> GetBucketNotificationAsync(GetBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Get bucket notification configuration
Parameters
Param
Description
GetBucketNotificationsArgs
GetBucketNotificationsArgs object encapsulating bucket name.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task<BucketNotification>
: The current notification configuration for the bucket.
Listed Exceptions:
InvalidBucketNameException
: upon invalid bucket name.
ConnectionException
: upon connection error.
AccessDeniedException
: upon access denial
InternalClientException
: upon internal library error.
BucketNotFoundException
: upon missing bucket
InvalidOperationException
: upon unsuccessful deserialization of xml data
Example
GetBucketNotificationsArgs args = new GetBucketNotificationsArgs()
.WithBucket(bucketName);
BucketNotification notifications = await minioClient.GetBucketNotificationAsync(args);
Console.WriteLine("Notifications is " + notifications.ToXML());
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task RemoveAllBucketNotificationsAsync(RemoveAllBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
Remove all notification configurations set on the bucket
Parameters
Param
Description
RemoveAllBucketNotificationsArgs
RemoveAllBucketNotificationsArgs args encapsulating the bucket name.
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
RemoveAllBucketNotificationsArgs args = new RemoveAllBucketNotificationsArgs()
.WithBucket(bucketName);
await minioClient.RemoveAllBucketNotificationsAsync(args);
Console.WriteLine("Notifications successfully removed from the bucket " + bucketName);
catch (MinioException e)
Console.WriteLine("Error occurred: " + e);
Task GetObjectAsync(GetObjectArgs args, ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))
Downloads an object.
Parameters
Param
Description
GetObjectArgs
GetObjectArgs Argument Object encapsulating bucket, object names, version Id, ServerSideEncryption object, offset, length
cancellationToken
System.Threading.CancellationToken
Optional parameter. Defaults to default(CancellationToken)
Task
: Task callback returns an InputStream containing the object data.
Listed Exceptions:
InvalidBucketNameException
: upon invalid bucket name.
ConnectionException
: upon connection error.
InternalClientException
: upon internal library error.
Examples
// 1. With Bucket & Object names.
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
StatObjectArgs statObjectArgs = new StatObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject");
await minioClient.StatObjectAsync(statObjectArgs);
// Get input stream to have content of 'my-objectname' from 'my-bucketname'
GetObjectArgs getObjectArgs = new GetObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject")
.WithCallbackStream((stream) =>
stream.CopyTo(Console.OpenStandardOutput());
await minioClient.GetObjectAsync(getObjectArgs);
catch (MinioException e)