API | 操作名 | 操作描述 |
设置存储桶 ACL | 设置指定存储桶的访问权限控制列表(ACL) | |
查询存储桶 ACL | 查询指定存储桶的访问权限控制列表(ACL) |
API | 操作名 | 操作描述 |
设置对象 ACL | 设置存储桶中某个对象的访问控制列表 | |
查询对象 ACL | 查询对象的访问控制列表 |
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";PutBucketACLRequest request = new PutBucketACLRequest(bucket);//设置私有读写权限request.SetCosACL(CosACL.Private);//授予1131975903账号读权限COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount();readAccount.AddGrantAccount("1131975903", "1131975903");request.SetXCosGrantRead(readAccount);//执行请求PutBucketACLResult result = cosXml.PutBucketACL(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";GetBucketACLRequest request = new GetBucketACLRequest(bucket);//执行请求GetBucketACLResult result = cosXml.GetBucketACL(request);//存储桶的 ACL 信息AccessControlPolicy acl = result.accessControlPolicy;}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
// 因为存储桶 ACL 最多1000条,为避免 ACL 达到上限,// 非必须情况不建议给对象单独设置 ACL(对象默认继承 bucket 权限).try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";string key = "exampleobject"; //对象键PutObjectACLRequest request = new PutObjectACLRequest(bucket, key);//设置私有读写权限request.SetCosACL(CosACL.Private);//授予1131975903账号读权限COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount();readAccount.AddGrantAccount("1131975903", "1131975903");request.SetXCosGrantRead(readAccount);//执行请求PutObjectACLResult result = cosXml.PutObjectACL(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000";string key = "exampleobject"; //对象键GetObjectACLRequest request = new GetObjectACLRequest(bucket, key);//执行请求GetObjectACLResult result = cosXml.GetObjectACL(request);//对象的 ACL 信息AccessControlPolicy acl = result.accessControlPolicy;}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
本页内容是否解决了您的问题?