API | 操作名 | 操作描述 |
设置存储桶 ACL | 设置指定存储桶的访问权限控制列表(ACL) | |
查询存储桶 ACL | 查询指定存储桶的访问权限控制列表(ACL) |
API | 操作名 | 操作描述 |
设置对象 ACL | 设置存储桶中某个对象的访问控制列表 | |
查询对象 ACL | 查询对象的访问控制列表 |
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";PutBucketACLRequest putBucketACLRequest = new PutBucketACLRequest(bucket);// 设置 bucket 访问权限putBucketACLRequest.setXCOSACL("public-read");// 赋予被授权者读的权限ACLAccount readACLS = new ACLAccount();readACLS.addAccount("100000000001", "100000000001");putBucketACLRequest.setXCOSGrantRead(readACLS);// 赋予被授权者写的权限ACLAccount writeACLS = new ACLAccount();writeACLS.addAccount("100000000001", "100000000001");putBucketACLRequest.setXCOSGrantWrite(writeACLS);// 赋予被授权者读写的权限ACLAccount 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;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 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;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键。PutObjectACLRequest putObjectACLRequest = new PutObjectACLRequest(bucket,cosPath);// 设置 对象 访问权限putObjectACLRequest.setXCOSACL("public-read");// 赋予被授权者读的权限ACLAccount readACLS = new ACLAccount();readACLS.addAccount("100000000001", "100000000001");putObjectACLRequest.setXCOSGrantRead(readACLS);// 赋予被授权者读写的权限ACLAccount 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;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";String cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即对象键。GetObjectACLRequest getBucketACLRequest = new GetObjectACLRequest(bucket,cosPath);cosXmlService.getObjectACLAsync(getBucketACLRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetObjectACLResult getObjectACLResult = (GetObjectACLResult) result;}// 如果您使用 kotlin 语言来调用,请注意回调方法中的异常是可空的,否则不会回调 onFail 方法,即:// clientException 的类型为 CosXmlClientException?,serviceException 的类型为 CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
本页内容是否解决了您的问题?