API | Operation | Description |
Setting a bucket ACL | Sets an ACL for a bucket | |
Querying a bucket ACL | Queries the ACL of a bucket |
API | Operation | Description |
Setting an object ACL | Sets an ACL for an object in a bucket | |
Querying an object ACL | Queries the ACL of an object |
try{// Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";PutBucketACLRequest request = new PutBucketACLRequest(bucket);// Set private read and write permissionsrequest.SetCosACL(CosACL.Private);// Grant read permission for account 1131975903COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount();readAccount.AddGrantAccount("1131975903", "1131975903");request.SetXCosGrantRead(readAccount);// Execute the requestPutBucketACLResult result = cosXml.PutBucketACL(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";GetBucketACLRequest request = new GetBucketACLRequest(bucket);// Execute the requestGetBucketACLResult result = cosXml.GetBucketACL(request);// Bucket ACL informationAccessControlPolicy acl = result.accessControlPolicy;}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
// To avoid reaching the upper limit of 1,000 bucket ACLs,// we do not recommend setting an object ACL for a single object unless absolutely necessary. The object will inherit bucket permissions by default.try{// Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";string key = "exampleobject"; // Object keyPutObjectACLRequest request = new PutObjectACLRequest(bucket, key);// Set private read and write permissionsrequest.SetCosACL(CosACL.Private);// Grant read permission for account 1131975903COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount();readAccount.AddGrantAccount("1131975903", "1131975903");request.SetXCosGrantRead(readAccount);// Execute the requestPutObjectACLResult result = cosXml.PutObjectACL(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";string key = "exampleobject"; // Object keyGetObjectACLRequest request = new GetObjectACLRequest(bucket, key);// Execute the requestGetObjectACLResult result = cosXml.GetObjectACL(request);// Object ACL informationAccessControlPolicy acl = result.accessControlPolicy;}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
Apakah halaman ini membantu?