API | 操作名 | 操作描述 |
设置存储桶策略 | 设置指定存储桶的权限策略 | |
查询存储桶策略 | 查询指定存储桶的权限策略 | |
删除存储桶策略 | 删除指定存储桶的权限策略 |
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";// 权限策略,详情请参见 访问管理策略语法 https://www.tencentcloud.com/document/product/436/12469?from_cn_redirect=1#.E7.AD.96.E7.95.A5.E8.AF.AD.E6.B3.95String policy = "{\\n" +" \\"Statement\\": [\\n" +" {\\n" +" \\"Principal\\": {\\n" +" \\"qcs\\": [\\n" +" \\"qcs::cam::uin/100000000001:uin/100000000011\\"\\n" +" ]\\n" +" },\\n" +" \\"Effect\\": \\"allow\\",\\n" +" \\"Action\\": [\\n" +" \\"name/cos:GetBucket\\"\\n" +" ],\\n" +" \\"Resource\\": [\\n" +" \\"qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*\\"\\n" +" ]\\n" +" }\\n" +" ],\\n" +" \\"version\\": \\"2.0\\"\\n" +"}";PutBucketPolicyRequest putBucketPolicyRequest =new PutBucketPolicyRequest(bucket, policy);cosXmlService.putBucketPolicyAsync(putBucketPolicyRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {// 详细字段请查看api文档或者SDK源码PutBucketPolicyResult putBucketPolicyResult =(PutBucketPolicyResult) 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";final GetBucketPolicyRequest getBucketPolicyRequest =new GetBucketPolicyRequest(bucket);cosXmlService.getBucketPolicyAsync(getBucketPolicyRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {// 详细字段请查看api文档或者SDK源码GetBucketPolicyResult getBucketPolicyResult =(GetBucketPolicyResult) result;String policy = getBucketPolicyResult.policy;}// 如果您使用 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";DeleteBucketPolicyRequest deleteBucketPolicyRequest =new DeleteBucketPolicyRequest(bucket);cosXmlService.deleteBucketPolicyAsync(deleteBucketPolicyRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {// 详细字段请查看api文档或者SDK源码DeleteBucketPolicyResult deleteBucketPolicyResult =(DeleteBucketPolicyResult) 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();}}});
本页内容是否解决了您的问题?