.NET Client API Reference
初始化 MinIO Client 对象。
MinIO
MinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io")
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.WithSSL()
.Build();
AWS S3
MinioClient minioClient = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
.WithSSL()
.Build();
Bucket operations |
对象操作 |
预签名操作 |
Bucket Policy 操作 |
|---|---|---|---|
1. 构造函数
|
创建MinIO客户端对象,并指定终端节点。AccessKey、secretKey、region和sessionToken为可选参数,匿名访问时可省略。 |
客户端对象默认使用Http访问。要使用Https,请链式调用WithSSL()方法到客户端对象以使用安全传输协议 |
参数
Param |
类型 |
描述 |
|---|---|---|
|
字符串 |
endPoint 是一个 URL、域名、IPv4 地址或 IPv6 地址。有效端点如下: |
s3.amazonaws.com |
||
play.min.io |
||
localhost |
||
play.min.io |
||
|
字符串 |
accessKey 类似于用户ID,用于唯一标识您的账户。此字段为可选字段,匿名访问时可省略。 |
|
字符串 |
secretKey 是您账户的密码。此字段为可选字段,匿名访问时可省略。 |
|
字符串 |
呼叫应发送到的区域。此字段为可选字段,可以省略。 |
|
字符串 |
如果使用临时访问凭证,需要设置 sessionToken |
安全访问 (TLS) |
|---|
|
代理 |
|---|
|
|
创建 MinIO 客户端。该客户端提供一个空对象,可通过链式调用仅填充所需的成员变量。 |
下一步重要操作是连接到端点。您可以在客户端对象上链式调用重载方法 WithEndpoint() 进行连接。 |
该客户端对象默认也使用Http访问。要使用Https,请链式调用WithSSL()方法到客户端对象以使用安全传输协议。 |
要使用非匿名访问,请将 WithCredentials() 方法链式调用到客户端对象,同时提供访问密钥和秘密密钥。 |
最后链式调用 Build() 方法来获取最终构建完成的客户端对象。 |
端点 |
|---|
|
返回类型 |
异常 |
|---|---|
|
列出的异常: |
示例
MinIO
// 1. Using Builder with public MinioClient(), Endpoint, Credentials & Secure connection
MinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io")
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.WithSSL()
.Build()
// 2. Using Builder with public MinioClient(), Endpoint, Credentials & Secure connection
MinioClient minioClient = new MinioClient()
.WithEndpoint("play.min.io", 9000, true)
.WithCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.Build()
// 3. Initializing minio client with proxy
IWebProxy proxy = new WebProxy("192.168.0.1", 8000);
MinioClient minioClient = new MinioClient()
.WithEndpoint("my-ip-address:9000")
.WithCredentials("minio", "minio123")
.WithSSL()
.WithProxy(proxy)
.Build();
AWS S3
// 1. public MinioClient(String endpoint, String accessKey, String secretKey)
MinioClient s3Client = new MinioClient("s3.amazonaws.com",
accessKey:"YOUR-ACCESSKEYID",
secretKey:"YOUR-SECRETACCESSKEY");
// 2. Using Builder with public MinioClient(), Endpoint, Credentials & Secure connection
MinioClient minioClient = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY")
.WithSSL()
.Build()
2. 存储桶操作
MakeBucketAsync(string bucketName, string location = "us-east-1")
Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken))
创建一个新的存储桶。
参数
Param |
类型 |
描述 |
|---|---|---|
|
字符串 |
存储桶的名称 |
|
字符串 |
可选参数。对于AWS请求,默认为 us-east-1 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// Create bucket if it doesn't exist.
bool found = await minioClient.BucketExistsAsync("mybucket");
if (found)
{
Console.WriteLine("mybucket already exists");
}
else
{
// Create bucket 'my-bucketname'.
await minioClient.MakeBucketAsync("mybucket");
Console.WriteLine("mybucket is created successfully");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
MakeBucketAsync(MakeBucketArgs args)
Task MakeBucketAsync(MakeBucketArgs args, CancellationToken cancellationToken = default(CancellationToken))
创建一个新的存储桶。
参数
Param |
类型 |
描述 |
|---|---|---|
|
MakeBucketArgs |
Arguments 对象 - 名称、位置。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// Create bucket if it doesn't exist.
bool found = await minioClient.BucketExistsAsync(bktExistArgs);
if (found)
{
Console.WriteLine(bktExistArgs.BucketName +" already exists");
}
else
{
// Create bucket 'my-bucketname'.
await minioClient.MakeBucketAsync(mkBktArgs);
Console.WriteLine(mkBktArgs.BucketName + " is created successfully");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
ListBucketsAsync()
Task<ListAllMyBucketsResult> ListBucketsAsync(CancellationToken cancellationToken = default(CancellationToken))
列出所有存储桶。
Param |
类型 |
描述 |
|---|---|---|
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
BucketExistsAsync(string bucketName)
Task<bool> BucketExistsAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
检查存储桶是否存在。
参数
Param |
类型 |
描述 |
|---|---|---|
|
字符串 |
存储桶的名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
BucketExistsAsync(BucketExistsArgs)
Task<bool> BucketExistsAsync(BucketExistsArgs args, CancellationToken cancellationToken = default(CancellationToken))
检查存储桶是否存在。
参数
Param |
类型 |
描述 |
|---|---|---|
|
BucketExistsArgs |
参数对象 - 存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
RemoveBucketAsync(string bucketName)
Task RemoveBucketAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
删除一个存储桶。
注意:- removeBucket 不会删除存储桶内的对象。需要使用 removeObject API 来删除对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
字符串 |
存储桶的名称 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
任务 |
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// 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");
}
else
{
Console.WriteLine("mybucket does not exist");
}
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
RemoveBucketAsync(RemoveBucketArgs args)
Task RemoveBucketAsync(RemoveBucketArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除一个存储桶。
注意:- removeBucket 不会删除存储桶内的对象。需要使用 removeObject API 来删除对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveBucketArgs |
Arguments Object - bucket name |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
任务 |
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// 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");
}
else
{
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
}
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
public async TaskGetVersioningAsync(GetVersioningArgs args)
Task<VersioningConfiguration> GetVersioningAsync(GetVersioningArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶的版本控制信息。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetVersioningArgs |
Arguments Object - 存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
无 |
Example
try
{
// 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);
}
else
{
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
public async Task SetVersioningAsync(SetVersioningArgs args)
Task SetVersioningAsync(SetVersioningArgs args, CancellationToken cancellationToken = default(CancellationToken))
为存储桶设置版本控制为启用或暂停状态。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetVersioningArgs |
参数对象 - 存储桶名称,版本控制状态。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
无 |
Example
try
{
// Check whether 'mybucket' exists or not.
bool found = minioClient.BucketExistsAsync(bktExistsArgs);
if (found)
{
var args = new SetVersioningArgs("mybucket")
.WithSSL()
.WithVersioningEnabled();
await minio.SetVersioningAsync(setArgs);
}
else
{
Console.WriteLine(bktExistsArgs.BucketName + " does not exist");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
SetBucketEncryptionAsync(SetBucketEncryptionArgs args)
Task SetBucketEncryptionAsync(SetBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken));
设置存储桶的加密配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetBucketEncryptionArgs |
SetBucketEncryptionArgs 参数对象,包含存储桶和加密配置 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
GetBucketEncryptionAsync(GetBucketEncryptionArgs args)
Task<ServerSideEncryptionConfiguration> GetBucketEncryptionAsync(GetBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶的加密配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetBucketEncryptionArgs |
GetBucketEncryptionArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
ServerSideEncryptionConfiguration包含存储桶加密配置的对象。
Example
try
{
// 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);
}
RemoveBucketEncryptionAsync(RemoveBucketEncryptionArgs args)
Task RemoveBucketEncryptionAsync(RemoveBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))
移除对象的存储桶加密配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveBucketEncryptionArgs |
RemoveBucketEncryptionArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
SetBucketLifecycleAsync(SetBucketLifecycleArgs args)
Task SetBucketLifecycleAsync(SetBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置存储桶的生命周期配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetBucketLifecycleArgs |
SetBucketLifecycleArgs 参数对象,包含存储桶名称和要设置的生命周期配置 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
GetBucketLifecycleAsync(GetBucketLifecycleArgs args)
Task<LifecycleConfiguration> GetBucketLifecycleAsync(GetBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶的生命周期配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetBucketLifecycleArgs |
GetBucketLifecycleArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
RemoveBucketLifecycleAsync(RemoveBucketLifecycleArgs args)
Task RemoveBucketLifecycleAsync(RemoveBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除存储桶的生命周期配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveBucketLifecycleArgs |
RemoveBucketLifecycleArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
SetBucketReplicationAsync(SetBucketReplicationArgs args)
Task SetBucketReplicationAsync(SetBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置存储桶的复制配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetBucketReplicationArgs |
SetBucketReplicationArgs 参数对象,包含存储桶名称和要设置的复制配置 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
GetBucketReplicationAsync(GetBucketReplicationArgs args)
Task<ReplicationConfiguration> GetBucketReplicationAsync(GetBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶的复制配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetBucketReplicationArgs |
GetBucketReplicationArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
RemoveBucketReplicationAsync(RemoveBucketReplicationArgs args)
Task RemoveBucketReplicationAsync(RemoveBucketReplicationArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除存储桶的复制配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveBucketReplicationArgs |
RemoveBucketReplicationArgs 参数对象(包含存储桶名称) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
ListObjectsAsync(ListObjectArgs args)
IObservable<Item> ListObjectsAsync(ListObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
列出存储桶中的所有对象(如果存在版本 ID,则包含版本 ID)。
参数
Param |
类型 |
描述 |
|---|---|---|
|
ListObjectArgs |
ListObjectArgs 对象 - 封装了存储桶名称、前缀、递归显示、显示版本信息。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
无 |
Example
try
{
// 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}"));
}
else
{
Console.WriteLine("mybucket does not exist");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
try
{
// 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}"));
}
else
{
Console.WriteLine("mybucket does not exist");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
SetObjectLockConfigurationAsync(SetObjectLockConfigurationArgs args)
Task SetObjectLockConfigurationAsync(SetObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置存储桶中的对象锁定配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetObjectLockConfigurationArgs |
SetObjectLockConfigurationArgs 参数对象,包含要设置的存储桶和锁定配置 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
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);
}
GetObjectLockConfigurationAsync(GetObjectLockConfigurationArgs args)
Task<ObjectLockConfiguration> GetObjectLockConfigurationAsync(GetObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶的对象锁定配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetObjectLockConfigurationArgs |
GetObjectLockConfigurationArgs 参数对象包含存储桶名称 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
RemoveObjectLockConfigurationAsync(RemoveObjectLockConfigurationArgs args)
Task RemoveObjectLockConfigurationAsync(RemoveObjectLockConfigurationArgs args, CancellationToken cancellationToken = default(CancellationToken))
移除存储桶上的对象锁定配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveObjectLockConfigurationArgs |
RemoveObjectLockConfigurationArgs 参数对象,包含存储桶名称 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
// 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);
}
ListIncompleteUploads(ListIncompleteUploadsArgs args)
IObservable<Upload> ListIncompleteUploads(ListIncompleteUploadsArgs args, CancellationToken cancellationToken = default(CancellationToken))
列出存储桶中部分上传的对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
ListIncompleteUploadsArgs |
ListIncompleteUploadsArgs 对象 - 封装了存储桶名称、前缀、是否递归显示参数。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
无 |
Example
try
{
// 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}"));
}
else
{
Console.WriteLine("mybucket does not exist");
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
ListenBucketNotificationsAsync(ListenBucketNotificationsArgs args)
IObservable<MinioNotificationRaw> ListenBucketNotificationsAsync(ListenBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
订阅存储桶变更通知(仅限 Minio 的扩展功能)
参数
Param |
类型 |
描述 |
|---|---|---|
|
ListenBucketNotificationsArgs |
ListenBucketNotificationsArgs 对象 - 封装了存储桶名称、事件列表、前缀和后缀。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
无 |
Example
try
{
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);
}
GetPolicyAsync(GetPolicyArgs args)
Task<String> GetPolicyAsync(GetPolicyArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶策略。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetPolicyArgs |
GetPolicyArgs 对象封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
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);
}
SetPolicyAsync(SetPolicyArgs args)
Task SetPolicyAsync(SetPolicyArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置存储桶策略。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetPolicyArgs |
SetPolicyArgs 对象,封装了存储桶名称和作为 JSON 字符串的策略。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
任务 |
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
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))
设置指定存储桶的通知配置
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetBucketNotificationsArgs |
SetBucketNotificationsArgs 对象封装了存储桶名称和通知配置对象。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
任务 |
列出的异常: |
|
|
|
|
|
|
|
|
Example
try
{
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);
}
GetBucketNotificationAsync(GetBucketNotificationsArgs args)
Task<BucketNotification> GetBucketNotificationAsync(GetBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取存储桶通知配置
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetBucketNotificationsArgs |
GetBucketNotificationsArgs 对象封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
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);
}
RemoveAllBucketNotificationsAsync(RemoveAllBucketNotificationsArgs args)
Task RemoveAllBucketNotificationsAsync(RemoveAllBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除桶上设置的所有通知配置
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveAllBucketNotificationsArgs |
RemoveAllBucketNotificationsArgs 参数封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
``任务`: |
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
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);
}
3. Object operations
GetObjectAsync(GetObjectArgs args, ServerSideEncryption sse)
Task GetObjectAsync(GetObjectArgs args, ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))
下载对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetObjectArgs |
GetObjectArgs 参数对象,封装了存储桶名称、对象名称、版本ID、服务器端加密对象、偏移量和长度 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
示例
// 1. With Bucket & Object names.
try
{
// 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)
{
Console.WriteLine("Error occurred: " + e);
}
// 2. With Offset Length specifying a range of bytes & the object as a stream.
try
{
// 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")
.WithOffset(1024L)
.WithObjectSize(10L)
.WithCallbackStream((stream) =>
{
stream.CopyTo(Console.OpenStandardOutput());
});
await minioClient.GetObjectAsync(getObjectArgs);
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
// 3. Downloads and saves the object as a file in the local filesystem.
try
{
// Check whether the object exists using statObjectAsync().
// If the object is not found, statObjectAsync() 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);
// Gets the object's data and stores it in photo.jpg
GetObjectArgs getObjectArgs = new GetObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject")
.WithFileName("photo.jpg");
await minioClient.GetObjectAsync(getObjectArgs);
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
PutObjectAsync(PutObjectArgs args)
Task PutObjectAsync(PutObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
PutObjectAsync: 从文件或流上传对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
PutObjectArgs |
参数对象 - 存储桶名称、对象名称、文件名、对象数据流、对象大小、内容类型、对象元数据、服务器端加密等。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
单个对象的最大大小限制为5TB。putObject会自动将大于5MiB的对象分块上传。上传的数据会使用MD5SUM签名进行严格验证。
try
{
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
PutObjectArgs putObjectArgs = new PutObjectArgs()
.WithBucket("mybucket")
.WithObject("island.jpg")
.WithFilename("/mnt/photos/island.jpg")
.WithContentType("application/octet-stream")
.WithServerSideEncryption(ssec);
await minio.PutObjectAsync(putObjectArgs);
Console.WriteLine("island.jpg is uploaded successfully");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
StatObjectAsync(StatObjectArgs args)
Task<ObjectStat> StatObjectAsync(StatObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取对象的元数据。
参数
Param |
类型 |
描述 |
|---|---|---|
|
StatObjectArgs |
StatObjectArgs 参数对象,包含存储桶名称、对象名称和服务端加密对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
try
{
// Get the metadata of the object.
StatObjectArgs statObjectArgs = new StatObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject");
ObjectStat objectStat = await minioClient.StatObjectAsync(statObjectArgs);
Console.WriteLine(objectStat);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
CopyObjectAsync(CopyObjectArgs args)
Task<CopyObjectResult> CopyObjectAsync(CopyObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
将内容从 objectName 复制到 destObjectName。
参数
Param |
类型 |
描述 |
|---|---|---|
|
CopyObjectArgs |
参数对象 - 存储桶名称、对象名称、目标存储桶名称、目标对象名称、复制条件、元数据、源服务器端加密、目标服务器端加密等。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
此API执行从给定源对象到目标对象的服务器端复制操作。
try
{
CopyConditions copyConditions = new CopyConditions();
copyConditions.setMatchETagNone("TestETag");
ServerSideEncryption sseSrc, sseDst;
// Uncomment to specify source and destination Server-side encryption options
/*
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
sseSrc = new SSEC(aesEncryption.Key);
sseDst = new SSES3();
*/
await minioClient.CopyObjectAsync("mybucket", "island.jpg", "mydestbucket", "processed.png", copyConditions, sseSrc:sseSrc, sseDest:sseDst);
Console.WriteLine("island.jpg is uploaded successfully");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
RemoveObjectAsync(RemoveObjectArgs args)
Task RemoveObjectAsync(RemoveObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除一个对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveObjectArgs |
Arguments 对象。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
// 1. Remove object myobject from the bucket mybucket.
try
{
RemoveObjectArgs rmArgs = new RemoveObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject");
await minioClient.RemoveObjectAsync(args);
Console.WriteLine("successfully removed mybucket/myobject");
}
catch (MinioException e)
{
Console.WriteLine("Error: " + e);
}
// 2. Remove one version of object myobject with versionID from mybucket.
try
{
RemoveObjectArgs rmArgs = new RemoveObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject")
.WithVersionId("versionId");
await minioClient.RemoveObjectAsync(args);
Console.WriteLine("successfully removed mybucket/myobject{versionId}");
}
catch (MinioException e)
{
Console.WriteLine("Error: " + e);
}
RemoveObjectsAsync(RemoveObjectsArgs args)
Task<IObservable<DeleteError>> RemoveObjectsAsync(RemoveObjectsArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除对象列表或对象版本列表。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveObjectsArgs |
Arguments Object - 存储桶名称,要删除的对象列表或元组列表(元组包含对象名称和版本ID列表)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
// 1. Remove list of objects in objectNames from the bucket bucketName.
try
{
string bucketName = "mybucket"
List<String> objectNames = new LinkedList<String>();
objectNames.add("my-objectname1");
objectNames.add("my-objectname2");
objectNames.add("my-objectname3");
RemoveObjectsAsync rmArgs = new RemoveObjectsAsync()
.WithBucket(bucketName)
.WithObjects(objectNames);
IObservable<DeleteError> observable = await minio.RemoveObjectAsync(rmArgs);
IDisposable subscription = observable.Subscribe(
deleteError => Console.WriteLine("Object: {0}", deleteError.Key),
ex => Console.WriteLine("OnError: {0}", ex),
() =>
{
Console.WriteLine("Removed objects from " + bucketName + "\n");
});
}
catch (MinioException e)
{
Console.WriteLine("Error: " + e);
}
// 2. Remove list of objects (only specific versions mentioned in Version ID list) from the bucket bucketName
try
{
string bucketName = "mybucket";
string objectName = "myobject1";
List<string> versionIDs = new List<string>();
versionIDs.Add("abcobject1version1dce");
versionIDs.Add("abcobject1version2dce");
versionIDs.Add("abcobject1version3dce");
List<Tuple<string, string>> objectsVersions = new List<Tuple<string, string>>();
objectsVersions.Add(new Tuple<string, List<string>>(objectName, versionIDs));
objectsVersions.Add(new Tuple<string, string>("myobject2" "abcobject2version1dce"));
objectsVersions.Add(new Tuple<string, string>("myobject2", "abcobject2version2dce"));
objectsVersions.Add(new Tuple<string, string>("myobject2", "abcobject2version3dce"));
RemoveObjectsAsync rmArgs = new RemoveObjectsAsync()
.WithBucket(bucketName)
.WithObjectsVersions(objectsVersions);
IObservable<DeleteError> observable = await minio.RemoveObjectsAsync(rmArgs);
IDisposable subscription = observable.Subscribe(
deleteError => Console.WriteLine("Object: {0}", deleteError.Key),
ex => Console.WriteLine("OnError: {0}", ex),
() =>
{
Console.WriteLine("Listed all delete errors for remove objects on " + bucketName + "\n");
});
}
catch (MinioException e)
{
Console.WriteLine("Error: " + e);
}
RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args)
Task RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args, CancellationToken cancellationToken = default(CancellationToken))
删除部分上传的对象。
参数
Param |
类型 |
描述 |
|---|---|---|
|
RemoveIncompleteUploadArgs |
封装了存储桶和对象名称的 RemoveIncompleteUploadArgs 对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
try
{
// Removes partially uploaded objects from buckets.
RemoveIncompleteUploadArgs args = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minioClient.RemoveIncompleteUploadAsync(args);
Console.WriteLine("successfully removed all incomplete upload session of my-bucketname/my-objectname");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
SelectObjectContentAsync(SelectObjectContentArgs args)
Task<SelectResponseStream> SelectObjectContentAsync(SelectObjectContentArgs args, CancellationToken cancellationToken = default(CancellationToken))
将对象作为流下载。
参数
Param |
类型 |
描述 |
|
|---|---|---|---|
|
SelectObjectContentArgs |
SelectObjectContent 异步操作选项 |
必需参数。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
Example
try
{
var opts = new SelectObjectOptions()
{
ExpressionType = QueryExpressionType.SQL,
Expression = "select count(*) from s3object",
InputSerialization = new SelectObjectInputSerialization()
{
CompressionType = SelectCompressionType.NONE,
CSV = new CSVInputOptions()
{
FileHeaderInfo = CSVFileHeaderInfo.None,
RecordDelimiter = "\n",
FieldDelimiter = ",",
}
},
OutputSerialization = new SelectObjectOutputSerialization()
{
CSV = new CSVOutputOptions()
{
RecordDelimiter = "\n",
FieldDelimiter = ",",
}
}
};
SelectObjectContentArgs args = SelectObjectContentArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithSelectObjectOptions(opts);
var resp = await minio.SelectObjectContentAsync(args);
resp.Payload.CopyTo(Console.OpenStandardOutput());
Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned);
Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned);
Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed);
if (resp.Progress != null)
{
Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
}
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args)
Task SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置对象的法定保留状态。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetObjectLegalHoldArgs |
SetObjectLegalHoldArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// Setting WithLegalHold true, sets Legal hold status to ON.
SetObjectLegalHoldArgs args = new SetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId)
.WithLegalHold(true);
await minio.SetObjectLegalHoldAsync(args);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args)
Task<bool> GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取对象的 Legal Hold 状态。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetObjectLegalHoldArgs |
GetObjectLegalHoldArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// Get Legal Hold status a object
var args = new GetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId);
bool enabled = await minio.GetObjectLegalHoldAsync(args);
Console.WriteLine("LegalHold Configuration STATUS for " + bucketName + "/" + objectName +
(!string.IsNullOrEmpty(versionId)?" with Version ID " + versionId: " ") +
" : " + (enabled?"ON":"OFF"));
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
SetObjectRetentionAsync(SetObjectRetentionArgs args)
Task SetObjectRetentionAsync(SetObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))
设置对象的保留配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
SetObjectRetentionArgs |
SetObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// Setting Retention Configuration of the object.
SetObjectRetentionArgs args = new SetObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithRetentionValidDays(numOfDays);
await minio.SetObjectRetentionAsync(args);
Console.WriteLine($"Assigned retention configuration to object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
GetObjectRetentionAsync(GetObjectRetentionArgs args)
Task<ObjectRetentionConfiguration> GetObjectRetentionAsync(GetObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取对象的保留配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
GetObjectRetentionArgs |
GetObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// Get Retention configuration of an object
var args = new GetObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName);
ObjectRetentionConfiguration config = await minio.GetObjectRetentionAsync(args);
Console.WriteLine($"Got retention configuration for object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
ClearObjectRetentionAsync(ClearObjectRetentionArgs args)
Task ClearObjectRetentionAsync(ClearObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))
清除对象的保留配置。
参数
Param |
类型 |
描述 |
|---|---|---|
|
ClearObjectRetentionArgs |
ClearObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选) |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Example
try
{
// Clearing the Retention Configuration of the object.
ClearObjectRetentionArgs args = new ClearObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.ClearObjectRetentionAsync(args);
Console.WriteLine($"Clears retention configuration to object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
4. 预签名操作
PresignedGetObjectAsync(PresignedGetObjectArgs args);
Task<string> PresignedGetObjectAsync(PresignedGetObjectArgs args)
生成用于HTTP GET操作的预签名URL。浏览器/移动客户端可以指向此URL直接下载对象,即使存储桶是私有的。此预签名URL可以设置以秒为单位的关联过期时间,超过该时间后将不再有效。默认过期时间设置为7天。
参数
Param |
类型 |
描述 |
|---|---|---|
|
PresignedGetObjectArgs |
PresignedGetObjectArgs 封装了存储桶名称、对象名称、过期时间、响应头和请求日期 |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
try
{
PresignedGetObjectArgs args = new PresignedGetObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject")
.WithExpiry(60 * 60 * 24);
String url = await minioClient.PresignedGetObjectAsync(args);
Console.WriteLine(url);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
PresignedPutObjectAsync(PresignedPutObjectArgs args)
Task<string> PresignedPutObjectAsync(PresignedPutObjectArgs args)
生成用于HTTP PUT操作的预签名URL。浏览器/移动客户端可以指向此URL,直接将对象上传到存储桶,即使该存储桶是私有的。此预签名URL可以设置关联的过期时间(以秒为单位),超过该时间后将不再可用。默认过期时间设置为7天。
参数
Param |
类型 |
描述 |
|---|---|---|
|
PresignedPutObjectArgs |
PresignedPutObjectArgs 参数对象,包含存储桶、对象名称和过期时间 |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
|
|
Example
try
{
PresignedPutObjectArgs args = PresignedPutObjectArgs()
.WithBucket("mybucket")
.WithObject("myobject")
.WithExpiry(60 * 60 * 24);
String url = await minioClient.PresignedPutObjectAsync(args);
Console.WriteLine(url);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
PresignedPostPolicy(PresignedPostPolicyArgs args)
Task<Dictionary<string, string>> PresignedPostPolicyAsync(PresignedPostPolicyArgs args)
允许为POST操作设置预签名URL的策略条件。可以设置接收对象上传的存储桶名称、键名前缀、过期策略等策略。
参数
Param |
类型 |
描述 |
|---|---|---|
|
PresignedPostPolicyArgs |
PresignedPostPolicyArgs 参数对象包含存储桶名称、对象名称及对象的 POST 策略。 |
返回类型 |
异常 |
|---|---|
|
列出的异常: |
|
|
|
|
|
Example
try
{
PostPolicy policy = new PostPolicy();
policy.SetContentType("image/png");
policy.SetUserMetadata("custom", "user");
DateTime expiration = DateTime.UtcNow;
policy.SetExpires(expiration.AddDays(10));
policy.SetKey("my-objectname");
policy.SetBucket("my-bucketname");
PresignedPostPolicyArgs args = PresignedPostPolicyArgs()
.WithBucket("my-bucketname")
.WithObject("my-objectname")
.WithPolicy(policy);
Dictionary<string, string> formData = minioClient.Api.PresignedPostPolicy(args);
string curlCommand = "curl ";
foreach (KeyValuePair<string, string> pair in formData)
{
curlCommand = curlCommand + " -F " + pair.Key + "=" + pair.Value;
}
curlCommand = curlCommand + " -F file=@/etc/bashrc https://s3.amazonaws.com/my-bucketname";
Console.WriteLine(curlCommand);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
客户端自定义设置
SetAppInfo(string appName, string appVersion)
将应用程序详情添加到 User-Agent。
参数
Param |
类型 |
描述 |
|---|---|---|
|
字符串 |
执行 API 请求的应用程序名称 |
|
字符串 |
执行 API 请求的应用程序版本 |
Example
// Set Application name and version to be used in subsequent API requests.
minioClient.SetAppInfo("myCloudApp", "1.0.0")
SetTraceOn(IRequestLogger logger = null)
启用 HTTP 跟踪功能。跟踪信息将写入标准输出。
参数
Param |
类型 |
描述 |
|---|---|---|
|
IRequestLogger |
接口实现 |
Example
// Set HTTP tracing on with default trace logger.
minioClient.SetTraceOn()
// Set custom logger for HTTP trace
minioClient.SetTraceOn(new JsonNetLogger())
SetTraceOff()
禁用 HTTP 跟踪。
Example
// Sets HTTP tracing off.
minioClient.SetTraceOff()