文档基于2025-10-10日社区最终版构建     
切换到英文版    进入演示系统    进入交流社区

MinIO Documentation

.NET Client API ReferenceSlack

初始化 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 操作

makeBucket

getObject

presignedGetObject

getBucketPolicy

listBuckets

putObject

presignedPutObject

setBucketPolicy

bucketExists

copyObject

presignedPostPolicy

setBucketNotification

removeBucket

statObject

getBucketNotification

listObjects

removeObject

removeAllBucketNotification

listIncompleteUploads

removeObjects

listenBucketNotifications

selectObjectContent

setVersioning

setLegalHold

getVersioning

getLegalHold

setBucketEncryption

setObjectTags

getBucketEncryption

getObjectTags

removeBucketEncryption

removeObjectTags

setBucketTags

setObjectRetention

getBucketTags

getObjectRetention

removeBucketTags

clearObjectRetention

setObjectLock

removeIncompleteUpload

getObjectLock

removeObjectLock

setBucketLifecycle

getBucketLifecycle

removeBucketLifecycle

setBucketReplication

getBucketReplication

removeBucketReplication

1. 构造函数

public MinioClient(string endpoint, string accessKey = "", string secretKey = "", string region = "", string sessionToken="")

创建MinIO客户端对象,并指定终端节点。AccessKey、secretKey、region和sessionToken为可选参数,匿名访问时可省略。

客户端对象默认使用Http访问。要使用Https,请链式调用WithSSL()方法到客户端对象以使用安全传输协议

参数

Param

类型

描述

endpoint

字符串

endPoint 是一个 URL、域名、IPv4 地址或 IPv6 地址。有效端点如下:

s3.amazonaws.com

play.min.io

localhost

play.min.io

accessKey

字符串

accessKey 类似于用户ID,用于唯一标识您的账户。此字段为可选字段,匿名访问时可省略。

secretKey

字符串

secretKey 是您账户的密码。此字段为可选字段,匿名访问时可省略。

region

字符串

呼叫应发送到的区域。此字段为可选字段,可以省略。

sessionToken

字符串

如果使用临时访问凭证,需要设置 sessionToken

安全访问 (TLS)

Chain .WithSSL() to MinIO Client object to use https instead of http.

代理

Chain .WithProxy(proxyObject) to MinIO Client object to use proxy

public MinioClient()

创建 MinIO 客户端。该客户端提供一个空对象,可通过链式调用仅填充所需的成员变量。

下一步重要操作是连接到端点。您可以在客户端对象上链式调用重载方法 WithEndpoint() 进行连接。

该客户端对象默认也使用Http访问。要使用Https,请链式调用WithSSL()方法到客户端对象以使用安全传输协议。

要使用非匿名访问,请将 WithCredentials() 方法链式调用到客户端对象,同时提供访问密钥和秘密密钥。

最后链式调用 Build() 方法来获取最终构建完成的客户端对象。

端点

Chain .WithEndpoint() to MinIO Client object to initialize the endpoint.

返回类型

异常

MinioClient

列出的异常:

示例

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

类型

描述

bucketName

字符串

存储桶的名称

region

字符串

可选参数。对于AWS请求,默认为 us-east-1

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

RedirectionException在服务器重定向后

InternalClientException发生内部库错误时

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

类型

描述

args

MakeBucketArgs

Arguments 对象 - 名称、位置。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

RedirectionException在服务器重定向后

InternalClientException发生内部库错误时

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

类型

描述

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ListAllMyBucketsResult>任务包含存储桶类型列表。

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

InvalidOperationException在XML数据反序列化失败时

ErrorResponseException执行失败时

InternalClientException发生内部库错误时

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

类型

描述

bucketName

字符串

存储桶的名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<bool>如果存储桶存在则为 true

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

ErrorResponseException执行失败时

InternalClientException发生内部库错误时

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

类型

描述

args

BucketExistsArgs

参数对象 - 存储桶名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<bool>如果存储桶存在则为 true

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

ErrorResponseException执行失败时

InternalClientException发生内部库错误时

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

类型

描述

bucketName

字符串

存储桶的名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

任务

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

ErrorResponseException执行失败时

InternalClientException发生内部库错误时

BucketNotFoundException当存储桶缺失时

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

类型

描述

args

RemoveBucketArgs

Arguments Object - bucket name

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

任务

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

AccessDeniedException访问被拒绝时

ErrorResponseException执行失败时

InternalClientException发生内部库错误时

BucketNotFoundException当存储桶缺失时

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

类型

描述

args

GetVersioningArgs

Arguments Object - 存储桶名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

VersioningConfiguration包含从响应中填充信息的版本控制配置。

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

类型

描述

args

SetVersioningArgs

参数对象 - 存储桶名称,版本控制状态。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task:

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

类型

描述

args

SetBucketEncryptionArgs

SetBucketEncryptionArgs 参数对象,包含存储桶和加密配置

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

GetBucketEncryptionArgs

GetBucketEncryptionArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ServerSideEncryptionConfiguration>

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

RemoveBucketEncryptionArgs

RemoveBucketEncryptionArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

SetBucketTagsAsync(SetBucketTagsArgs args)

Task SetBucketTagsAsync(SetBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

为存储桶设置标签。

参数

Param

类型

描述

args

SetBucketTagsArgs

SetBucketTagsArgs 参数对象,包含要设置的 bucket 和 tags

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Set Tags for the bucket
	SetBucketTagsArgs args = new SetBucketTagsArgs()
												.WithBucket(bucketName)
												.WithTagging(tags);
	await minio.SetBucketTagsAsync(args);
	Console.WriteLine($"Set Tags for bucket {bucketName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

GetBucketTagsAsync(GetBucketTagsArgs args)

Task<Tagging> GetBucketTagsAsync(GetBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

获取存储桶的标签。

参数

Param

类型

描述

args

GetBucketTagsArgs

GetBucketTagsArgs 参数对象,包含存储桶名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<Tagging>包含标签-值对的对象标记。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Get Bucket Tags for the bucket
	var args = new GetBucketTagsArgs()
						.WithBucket(bucketName);
	var tags = await minio.GetBucketTagsAsync(args);
	Console.WriteLine($"Got tags for bucket {bucketName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

RemoveBucketTagsAsync(RemoveBucketTagsArgs args)

Task RemoveBucketTagsAsync(RemoveBucketTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

删除存储桶的标签。

参数

Param

类型

描述

args

RemoveBucketTagsArgs

RemoveBucketTagsArgs 参数对象,包含存储桶名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Remove Bucket Encryption Configuration for the bucket
	var args = new RemoveBucketTagsArgs()
								.WithBucket(bucketName);
	await minio.RemoveBucketTagsAsync(args);
	Console.WriteLine($"Removed tags for bucket {bucketName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

SetBucketLifecycleAsync(SetBucketLifecycleArgs args)

Task SetBucketLifecycleAsync(SetBucketLifecycleArgs args, CancellationToken cancellationToken = default(CancellationToken))

设置存储桶的生命周期配置。

参数

Param

类型

描述

args

SetBucketLifecycleArgs

SetBucketLifecycleArgs 参数对象,包含存储桶名称和要设置的生命周期配置

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

GetBucketLifecycleArgs

GetBucketLifecycleArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<LifecycleConfiguration>LifecycleConfiguration 对象,其中包含生命周期配置详细信息。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

RemoveBucketLifecycleArgs

RemoveBucketLifecycleArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

SetBucketReplicationArgs

SetBucketReplicationArgs 参数对象,包含存储桶名称和要设置的复制配置

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

GetBucketReplicationArgs

GetBucketReplicationArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ReplicationConfiguration>ReplicationConfiguration 对象,其中包含复制配置详细信息。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

RemoveBucketReplicationArgs

RemoveBucketReplicationArgs 参数对象(包含存储桶名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

ListObjectArgs

ListObjectArgs 对象 - 封装了存储桶名称、前缀、递归显示、显示版本信息。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

IObservable<Item>一个可观察的条目流。

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

类型

描述

args

SetObjectLockConfigurationArgs

SetObjectLockConfigurationArgs 参数对象,包含要设置的存储桶和锁定配置

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

GetObjectLockConfigurationArgs

GetObjectLockConfigurationArgs 参数对象包含存储桶名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ObjectLockConfiguration>ObjectLockConfiguration 对象,包含锁定启用状态和对象锁定规则。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

RemoveObjectLockConfigurationArgs

RemoveObjectLockConfigurationArgs 参数对象,包含存储桶名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

BucketNotFoundException未找到指定名称的存储桶

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

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

类型

描述

args

ListIncompleteUploadsArgs

ListIncompleteUploadsArgs 对象 - 封装了存储桶名称、前缀、是否递归显示参数。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

IObservable<Upload> 一个可观察的上传对象。

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

类型

描述

args

ListenBucketNotificationsArgs

ListenBucketNotificationsArgs 对象 - 封装了存储桶名称、事件列表、前缀和后缀。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

IObservable<MinioNotificationRaw>一个 Observable 对象MinioNotificationRaw,其中包含原始 JSON 通知。使用Minio通知使用您选择的 JSON 库进行反序列化的类。

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

类型

描述

args

GetPolicyArgs

GetPolicyArgs 对象封装了存储桶名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<String>给定存储桶的当前存储桶策略(以 JSON 字符串形式呈现)。

列出的异常:

InvalidBucketNameException 当存储桶名称无效时。

InvalidObjectPrefixException遇到无效对象前缀时。

ConnectionException连接错误时。

AccessDeniedException访问被拒绝时

InternalClientException发生内部库错误时。

BucketNotFoundException当存储桶缺失时

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

类型

描述

args

SetPolicyArgs

SetPolicyArgs 对象,封装了存储桶名称和作为 JSON 字符串的策略。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

任务

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

InvalidBucketNameException 当存储桶名称无效时

InvalidObjectPrefixException对于无效对象前缀

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

类型

描述

args

SetBucketNotificationsArgs

SetBucketNotificationsArgs 对象封装了存储桶名称和通知配置对象。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

任务

列出的异常:

ConnectionException连接错误时

InternalClientException发生内部库错误时

InvalidBucketNameException 当存储桶名称无效时

InvalidOperationException在通知对象序列化失败时

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

类型

描述

args

GetBucketNotificationsArgs

GetBucketNotificationsArgs 对象封装了存储桶名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<BucketNotification>存储桶的当前通知配置。

列出的异常:

InvalidBucketNameException 当存储桶名称无效时。

ConnectionException连接错误时。

AccessDeniedException访问被拒绝时

InternalClientException发生内部库错误时。

BucketNotFoundException当存储桶缺失时

InvalidOperationException在XML数据反序列化失败时

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

类型

描述

args

RemoveAllBucketNotificationsArgs

RemoveAllBucketNotificationsArgs 参数封装了存储桶名称。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

``任务`:

列出的异常:

InvalidBucketNameException 当存储桶名称无效时。

ConnectionException连接错误时。

AccessDeniedException访问被拒绝时

InternalClientException发生内部库错误时。

BucketNotFoundException当存储桶缺失时

InvalidOperationException在XML数据序列化失败时

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

类型

描述

args

GetObjectArgs

GetObjectArgs 参数对象,封装了存储桶名称、对象名称、版本ID、服务器端加密对象、偏移量和长度

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task任务回调返回一个包含对象数据的 InputStream。

列出的异常:

InvalidBucketNameException当存储桶名称无效时。

ConnectionException连接错误时。

InternalClientException发生内部库错误时。

示例

// 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

类型

描述

args

PutObjectArgs

参数对象 - 存储桶名称、对象名称、文件名、对象数据流、对象大小、内容类型、对象元数据、服务器端加密等。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

EntityTooLargeException当建议的上传大小超过最大允许值时

UnexpectedShortReadException数据读取长度小于输入缓冲区大小

ArgumentNullException当输入流为空时

InvalidOperationException当输入到 PutObjectArgs 的值无效时

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

类型

描述

args

StatObjectArgs

StatObjectArgs 参数对象,包含存储桶名称、对象名称和服务端加密对象

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ObjectStat>填充的对象元数据。

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

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

类型

描述

args

CopyObjectArgs

参数对象 - 存储桶名称、对象名称、目标存储桶名称、目标对象名称、复制条件、元数据、源服务器端加密、目标服务器端加密等。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

ConnectionException连接错误时

InternalClientException发生内部库错误时

ArgumentException当缺少存储桶/对象名称时

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

类型

描述

args

RemoveObjectArgs

Arguments 对象。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

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

类型

描述

args

RemoveObjectsArgs

Arguments Object - 存储桶名称,要删除的对象列表或元组列表(元组包含对象名称和版本ID列表)。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

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

类型

描述

args

RemoveIncompleteUploadArgs

封装了存储桶和对象名称的 RemoveIncompleteUploadArgs 对象

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InternalClientException发生内部库错误时

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

类型

描述

args

SelectObjectContentArgs

SelectObjectContent 异步操作选项

必需参数。

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task任务回调返回一个包含选择结果的 SelectResponseStream。

列出的异常:

InvalidBucketNameException当存储桶名称无效时。

ConnectionException连接错误时。

InternalClientException发生内部库错误时。

ArgumentException当响应格式无效时

IOException数据不足

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

类型

描述

args

SetObjectLegalHoldArgs

SetObjectLegalHoldArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MissingObjectLockConfigurationException在创建存储桶时未启用对象锁定功能

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

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

类型

描述

args

GetObjectLegalHoldArgs

GetObjectLegalHoldArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<bool>如果启用了 LegalHold,则为 true,否则为 false。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MissingObjectLockConfigurationException在创建存储桶时未启用对象锁定功能

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

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

SetObjectTagsAsync(SetObjectTagsArgs args)

Task SetObjectTagsAsync(SetObjectTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

为对象设置标签。

参数

Param

类型

描述

args

SetObjectTagsArgs

SetObjectTagsArgs 参数对象,包含要设置的对象和标签

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Set Tags for the object
	SetObjectTagsArgs args = new new SetObjectTagsArgs()
												.WithBucket(bucketName)
												.WithObject(objectName)
												.WithTagging(tags);
	await minio.SetObjectTagsAsync(args);
	Console.WriteLine($"Set tags for object {bucketName}/{objectName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

GetObjectTagsAsync(GetObjectTagsArgs args)

Task<Tagging> GetObjectTagsAsync(GetObjectTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

获取对象的标签。

参数

Param

类型

描述

args

GetObjectTagsArgs

GetObjectTagsArgs 参数对象(包含对象名称)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<Tagging>Task包含标签-值对的对象。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Get Object Tags for the object
	var args = new GetObjectTagsArgs()
						.WithBucket(bucketName)
						.WithObject(objectName);
	var tags = await minio.GetObjectTagsAsync(args);
	Console.WriteLine($"Got tags for object {bucketName}/{objectName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

RemoveObjectTagsAsync(RemoveObjectTagsArgs args)

Task RemoveObjectTagsAsync(RemoveObjectTagsArgs args, CancellationToken cancellationToken = default(CancellationToken))

删除对象的标签。

参数

Param

类型

描述

args

RemoveObjectTagsArgs

RemoveObjectTagsArgs 参数对象,包含对象名称

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

UnexpectedMinioException在操作过程中遇到内部错误时

Example

try
{
	// Remove Tags for the object
	var args = new RemoveObjectTagsArgs()
								.WithBucket(bucketName)
								.WithObject(objectName);
	await minio.RemoveObjectTagsAsync(args);
	Console.WriteLine($"Removed tags for object {bucketName}/{objectName}.");
}
catch(MinioException e)
{
   Console.WriteLine("Error occurred: " + e);
}

SetObjectRetentionAsync(SetObjectRetentionArgs args)

Task SetObjectRetentionAsync(SetObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))

设置对象的保留配置。

参数

Param

类型

描述

args

SetObjectRetentionArgs

SetObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MissingObjectLockConfigurationException在创建存储桶时未启用对象锁定功能

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

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

类型

描述

args

GetObjectRetentionArgs

GetObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task<ObjectRetentionConfiguration>包含配置数据的 ObjectRetentionConfiguration 对象。

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MissingObjectLockConfigurationException在创建存储桶时未启用对象锁定功能

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

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

类型

描述

args

ClearObjectRetentionArgs

ClearObjectRetentionArgs 参数对象,包含存储桶名称、对象名称、版本ID(可选)

cancellationToken

System.Threading.CancellationToken

可选参数。默认为 default(CancellationToken)

返回类型

异常

Task

列出的异常:

AuthorizationException当访问密钥或密钥错误或未找到时

InvalidBucketNameException当存储桶名称无效时

InvalidObjectNameException对象名称无效时

BucketNotFoundException未找到指定名称的存储桶

ObjectNotFoundException未找到指定名称的对象

MissingObjectLockConfigurationException在创建存储桶时未启用对象锁定功能

MalFormedXMLException在 HTTP 请求验证失败时配置 XML

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

类型

描述

args

PresignedGetObjectArgs

PresignedGetObjectArgs 封装了存储桶名称、对象名称、过期时间、响应头和请求日期

返回类型

异常

Task<string>字符串包含下载对象的URL

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

InvalidExpiryRangeException当到期范围无效时。

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

类型

描述

args

PresignedPutObjectArgs

PresignedPutObjectArgs 参数对象,包含存储桶、对象名称和过期时间

返回类型

异常

Task<string>字符串包含用于上传对象的URL

列出的异常:

InvalidBucketNameException当存储桶名称无效时

InvalidKeyException当访问密钥或密钥无效时

ConnectionException连接错误时

InvalidExpiryRangeException当到期范围无效时。

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

类型

描述

args

PresignedPostPolicyArgs

PresignedPostPolicyArgs 参数对象包含存储桶名称、对象名称及对象的 POST 策略。

返回类型

异常

Task<Dictionary<string, string>>字符串到表单数据的映射表。

列出的异常:

InvalidBucketNameException当存储桶名称无效时

ConnectionException连接错误时

NoSuchAlgorithmException在签名计算过程中未找到请求的算法。

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

类型

描述

appName

字符串

执行 API 请求的应用程序名称

appVersion

字符串

执行 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

类型

描述

logger

IRequestLogger

接口实现Minio.IRequestLogger用于跟踪 HTTP 的序列化模型

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