.NET 客户端 API 参考
初始化 MinIO 客户端对象。
MinIO
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();
存储桶操作 |
对象操作 |
预签名操作 |
存储桶策略操作 |
---|---|---|---|
1. 构造函数
|
使用给定的端点创建 MinIO 客户端对象。AccessKey、secretKey、region 和 sessionToken 是可选参数,对于匿名访问可以省略。 |
客户端对象默认使用 Http 访问。要使用 Https,请将 WithSSL() 方法链接到客户端对象以使用安全传输协议。 |
参数
参数 |
类型 |
描述 |
---|---|---|
|
string |
endPoint 是一个 URL、域名、IPv4 地址或 IPv6 地址。有效的端点如下所示 |
s3.amazonaws.com |
||
play.min.io |
||
localhost |
||
play.min.io |
||
|
string |
accessKey 类似于唯一标识您的帐户的用户 ID。此字段是可选的,对于匿名访问可以省略。 |
|
string |
secretKey 是您帐户的密码。此字段是可选的,对于匿名访问可以省略。 |
|
string |
应进行调用的区域。此字段是可选的,可以省略。 |
|
string |
如果使用临时访问凭证,则需要设置 sessionToken。 |
安全访问 (TLS) |
---|
|
|
代理 |
---|
|
|
创建 MinIO 客户端。此客户端提供一个空对象,可与链接一起使用,以仅填充我们需要的成员变量。 |
下一步是连接到端点。您可以将其中一个重载的 WithEndpoint() 方法链接到客户端对象以进行连接。 |
此客户端对象也默认使用 Http 访问。要使用 Https,请将 WithSSL() 或 WithSSL(true) 方法链接到客户端对象以使用安全传输协议。 |
要使用非匿名访问,请将 WithCredentials() 方法与访问密钥和密钥链式连接到客户端对象。 |
最后,链式连接 Build() 方法以获取最终构建的客户端对象。 |
端点 |
---|
|
返回类型 |
异常 |
---|---|
|
列出的异常 |
示例
MinIO
// 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();
AWS S3
// 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();
2. 存储桶操作
MakeBucketAsync(string bucketName, string location = “us-east-1”)
Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken))
创建一个新的存储桶。
参数
参数 |
类型 |
描述 |
---|---|---|
|
string |
存储桶的名称 |
|
string |
可选参数。对于 AWS 请求,默认为 us-east-1 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
创建一个新的存储桶。
参数
参数 |
类型 |
描述 |
---|---|---|
|
MakeBucketArgs |
参数对象 - 名称、位置。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
列出所有存储桶。
参数 |
类型 |
描述 |
---|---|---|
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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))
检查存储桶是否存在。
参数
参数 |
类型 |
描述 |
---|---|---|
|
string |
存储桶的名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
检查存储桶是否存在。
参数
参数 |
类型 |
描述 |
---|---|---|
|
BucketExistsArgs |
参数对象 - 存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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 删除对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
string |
存储桶的名称 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
Task |
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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 删除对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveBucketArgs |
参数对象 - 存储桶名称 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
Task |
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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))
获取存储桶的版本控制信息。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetVersioningArgs |
参数对象 - 存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
无 |
示例
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))
将存储桶的版本控制设置为启用或暂停。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetVersioningArgs |
参数对象 - 存储桶名称、版本控制状态。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
无 |
示例
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));
设置存储桶的存储桶加密配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetBucketEncryptionArgs |
带有存储桶和加密配置的 SetBucketEncryptionArgs 参数对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
获取存储桶的存储桶加密配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetBucketEncryptionArgs |
带有存储桶名称的 GetBucketEncryptionArgs 参数对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
包含存储桶加密配置的 **ServerSideEncryptionConfiguration** 对象。
示例
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))
删除对象的存储桶加密配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveBucketEncryptionArgs |
带有存储桶名称的 RemoveBucketEncryptionArgs 参数对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
将生命周期配置设置为存储桶。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetBucketLifecycleArgs |
带有存储桶名称和要设置的生命周期配置的 SetBucketLifecycleArgs 参数对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
获取存储桶的生命周期配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetBucketLifecycleArgs |
带有存储桶名称的 GetBucketLifecycleArgs 参数对象 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
删除存储桶的生命周期配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveBucketLifecycleArgs |
RemoveBucketLifecycleArgs 参数对象,包含存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
设置存储桶的复制配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetBucketReplicationArgs |
SetBucketReplicationArgs 参数对象,包含存储桶名称和要设置的复制配置。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
获取存储桶的复制配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetBucketReplicationArgs |
GetBucketReplicationArgs 参数对象,包含存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
删除存储桶的复制配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveBucketReplicationArgs |
RemoveBucketReplicationArgs 参数对象,包含存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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)。
参数
参数 |
类型 |
描述 |
---|---|---|
|
ListObjectArgs |
ListObjectArgs 对象 - 封装了存储桶名称、前缀、是否递归显示、是否显示版本。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
无 |
示例
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))
设置存储桶的对象锁定配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetObjectLockConfigurationArgs |
SetObjectLockConfigurationArgs 参数对象,包含存储桶和要设置的锁定配置。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
获取存储桶的对象锁定配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetObjectLockConfigurationArgs |
GetObjectLockConfigurationArgs 参数对象,包含存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
删除存储桶上的对象锁定配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveObjectLockConfigurationArgs |
RemoveObjectLockConfigurationArgs 参数对象,包含存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
列出存储桶中部分上传的对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
ListIncompleteUploadsArgs |
ListIncompleteUploadsArgs 对象 - 封装了存储桶名称、前缀、是否递归显示。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
无 |
示例
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 独有扩展)。
参数
参数 |
类型 |
描述 |
---|---|---|
|
ListenBucketNotificationsArgs |
ListenBucketNotificationsArgs 对象 - 封装了存储桶名称、事件列表、前缀、后缀。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
无 |
示例
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))
获取存储桶策略。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetPolicyArgs |
GetPolicyArgs 对象,封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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))
在存储桶上设置策略。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetPolicyArgs |
SetPolicyArgs 对象,封装了存储桶名称和 JSON 字符串形式的策略。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
Task |
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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))
为给定的存储桶设置通知配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetBucketNotificationsArgs |
SetBucketNotificationsArgs 对象,封装了存储桶名称和通知配置对象。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
Task |
列出的异常 |
|
|
|
|
|
|
|
|
示例
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))
获取存储桶通知配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetBucketNotificationsArgs |
GetBucketNotificationsArgs 对象,封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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))
删除存储桶上设置的所有通知配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveAllBucketNotificationsArgs |
RemoveAllBucketNotificationsArgs 参数,封装了存储桶名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
``Task` |
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
示例
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. 对象操作
GetObjectAsync(GetObjectArgs args, ServerSideEncryption sse)
Task GetObjectAsync(GetObjectArgs args, ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))
下载对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetObjectArgs |
GetObjectArgs 参数对象,封装了存储桶、对象名称、版本 ID、ServerSideEncryption 对象、偏移量、长度。 |
|
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: 从文件或流上传对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
PutObjectArgs |
参数对象 - 存储桶名称、对象名称、文件名、对象数据流、对象大小、内容类型、对象元数据、操作执行进度、SSE 等。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
单个对象的最大大小限制为 5TB。 putObject 会透明地将大于 5MiB 的对象上传为多个部分。上传的数据使用 MD5SUM 签名进行仔细验证。
try
{
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
var progress = new Progress<ProgressReport>(progressReport =>
{
// Progress events are delivered asynchronously (see remark below)
Console.WriteLine(
$"Percentage: {progressReport.Percentage}% TotalBytesTransferred: {progressReport.TotalBytesTransferred} bytes");
if (progressReport.Percentage != 100)
Console.SetCursorPosition(0, Console.CursorTop - 1);
else Console.WriteLine();
});
PutObjectArgs putObjectArgs = new PutObjectArgs()
.WithBucket("mybucket")
.WithObject("island.jpg")
.WithFilename("/mnt/photos/island.jpg")
.WithContentType("application/octet-stream")
.WithServerSideEncryption(ssec)
.WithProgress(progress);
await minio.PutObjectAsync(putObjectArgs);
Console.WriteLine("island.jpg is uploaded successfully");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
备注:请注意,默认的 ProgressMinio.Helper.SyncProgress<T>
代替,但请确保您理解其含义。进度事件是同步发送的,因此它们可能在任意线程上调用(对于 UI 应用程序来说这主要是一个问题),并且执行长时间运行和/或阻塞操作会降低上传性能。
StatObjectAsync(StatObjectArgs args)
Task<ObjectStat> StatObjectAsync(StatObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
获取对象的元数据。
参数
参数 |
类型 |
描述 |
---|---|---|
|
StatObjectArgs |
StatObjectArgs 参数对象,包含存储桶、对象名称和服务器端加密对象。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
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。
参数
参数 |
类型 |
描述 |
---|---|---|
|
CopyObjectArgs |
参数对象 - 存储桶名称、对象名称、目标存储桶名称、目标对象名称、复制条件、元数据、源 SSE、目标 SSE 等。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
此 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))
删除对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveObjectArgs |
参数对象。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
// 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))
删除对象或对象版本的列表。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveObjectsArgs |
参数对象 - 存储桶名称、要删除的对象列表或包含元组 (对象名称、版本 ID 列表) 的元组列表。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
// 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))
删除部分上传的对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
RemoveIncompleteUploadArgs |
RemoveIncompleteUploadArgs 对象封装了存储桶和对象名称。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
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))
将对象下载为流。
参数
参数 |
类型 |
描述 |
|
---|---|---|---|
|
SelectObjectContentArgs |
SelectObjectContent 异步操作的选项。 |
必需参数。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
示例
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 is not 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))
设置对象的法律保留状态。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetObjectLegalHoldArgs |
SetObjectLegalHoldArgs 参数对象,包含存储桶、对象名称和版本 ID(可选)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
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))
获取对象的法律保留状态。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetObjectLegalHoldArgs |
GetObjectLegalHoldArgs 参数对象,包含存储桶、对象名称和版本 ID(可选)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
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))
将保留配置设置为对象。
参数
参数 |
类型 |
描述 |
---|---|---|
|
SetObjectRetentionArgs |
SetObjectRetentionArgs 参数对象,包含存储桶、对象名称和版本 ID(可选)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
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))
获取对象的保留配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
GetObjectRetentionArgs |
GetObjectRetentionArgs 参数对象,包含存储桶、对象名称和版本 ID(可选)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
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))
清除对象的保留配置。
参数
参数 |
类型 |
描述 |
---|---|---|
|
ClearObjectRetentionArgs |
ClearObjectRetentionArgs 参数对象,包含存储桶、对象名称和版本 ID(可选)。 |
|
System.Threading.CancellationToken |
可选参数。默认为 default(CancellationToken) |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
示例
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 天。
参数
参数 |
类型 |
描述 |
---|---|---|
|
PresignedGetObjectArgs |
PresignedGetObjectArgs 封装了存储桶、对象名称、过期时间、响应头和请求日期。 |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
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 天。
参数
参数 |
类型 |
描述 |
---|---|---|
|
PresignedPutObjectArgs |
PresignedPutObjectArgs 参数对象,包含存储桶、对象名称和过期时间。 |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
|
|
示例
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 设置策略条件。可以设置诸如接收对象上传的存储桶名称、密钥名称前缀、过期策略等策略。
参数
参数 |
类型 |
描述 |
---|---|---|
|
PresignedPostPolicyArgs |
PresignedPostPolicyArgs 参数对象,包含存储桶、对象名称和对象的 POST 策略。 |
返回类型 |
异常 |
---|---|
|
列出的异常 |
|
|
|
|
|
示例
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。
参数
参数 |
类型 |
描述 |
---|---|---|
|
string |
执行 API 请求的应用程序名称 |
|
string |
执行 API 请求的应用程序版本 |
示例
// Set Application name and version to be used in subsequent API requests.
minioClient.SetAppInfo("myCloudApp", "1.0.0")
SetTraceOn(IRequestLogger logger = null)
启用 HTTP 追踪。跟踪信息将写入标准输出。
参数
参数 |
类型 |
描述 |
---|---|---|
|
IRequestLogger |
实现 |
示例
// Set HTTP tracing on with default trace logger.
minioClient.SetTraceOn()
// Set custom logger for HTTP trace
minioClient.SetTraceOn(new JsonNetLogger())
SetTraceOff()
禁用 HTTP 追踪。
示例
// Sets HTTP tracing off.
minioClient.SetTraceOff()