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 |
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";PutBucketACLRequest putBucketACLRequest = new PutBucketACLRequest(bucket);// Set the bucket's access permissionsputBucketACLRequest.setXCOSACL("public-read");// Grant read permission.ACLAccount readACLS = new ACLAccount();readACLS.addAccount("100000000001", "100000000001");putBucketACLRequest.setXCOSGrantRead(readACLS);// Grant write permission.ACLAccount writeACLS = new ACLAccount();writeACLS.addAccount("100000000001", "100000000001");putBucketACLRequest.setXCOSGrantWrite(writeACLS);// Grant read and write permissionACLAccount writeandReadACLS = new ACLAccount();writeandReadACLS.addAccount("100000000001", "100000000001");putBucketACLRequest.setXCOSReadWrite(writeandReadACLS);cosXmlService.putBucketACLAsync(putBucketACLRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutBucketACLResult putBucketACLResult = (PutBucketACLResult) result;}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";GetBucketACLRequest getBucketACLRequest = new GetBucketACLRequest(bucket);cosXmlService.getBucketACLAsync(getBucketACLRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketACLResult getBucketACLResult = (GetBucketACLResult) result;}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; // The location identifier of the object in the bucket, i.e., the object keyPutObjectACLRequest putObjectACLRequest = new PutObjectACLRequest(bucket,cosPath);// Set the object's access permissionsputObjectACLRequest.setXCOSACL("public-read");// Grant read permission.ACLAccount readACLS = new ACLAccount();readACLS.addAccount("100000000001", "100000000001");putObjectACLRequest.setXCOSGrantRead(readACLS);// Grant read and write permissionACLAccount writeandReadACLS = new ACLAccount();writeandReadACLS.addAccount("100000000001", "100000000001");putObjectACLRequest.setXCOSReadWrite(writeandReadACLS);cosXmlService.putObjectACLAsync(putObjectACLRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutObjectACLResult putObjectACLResult = (PutObjectACLResult) result;}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; // The location identifier of the object in the bucket, i.e., the object keyGetObjectACLRequest getBucketACLRequest = new GetObjectACLRequest(bucket,cosPath);cosXmlService.getObjectACLAsync(getBucketACLRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetObjectACLResult getObjectACLResult = (GetObjectACLResult) result;}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Was this page helpful?