API | 操作名 | 操作描述 |
设置生命周期 | 设置存储桶的生命周期管理的配置 | |
查询生命周期 | 查询存储桶生命周期管理的配置 | |
删除生命周期 | 删除存储桶生命周期管理的配置 |
// 存储桶名称,由bucketname-appid 组成,appid必须填入,可以在COS控制台查看存储桶名称。 https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";PutBucketLifecycleRequest putBucketLifecycleRequest =new PutBucketLifecycleRequest(bucket);// 声明周期配置规则信息LifecycleConfiguration.Rule rule = new LifecycleConfiguration.Rule();rule.id = "Lifecycle ID";LifecycleConfiguration.Filter filter = new LifecycleConfiguration.Filter();// 指定规则所适用的前缀filter.prefix = "dir/";rule.filter = filter;// 指明规则是否启用rule.status = "Enabled";// 指明规则对应的动作在对象最后的修改日期过后多少天操作LifecycleConfiguration.Transition transition =new LifecycleConfiguration.Transition();transition.days = 100;transition.storageClass = COSStorageClass.STANDARD.getStorageClass();rule.transition = transition;putBucketLifecycleRequest.setRuleList(rule);cosXmlService.putBucketLifecycleAsync(putBucketLifecycleRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutBucketLifecycleResult putBucketLifecycleResult =(PutBucketLifecycleResult) 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";GetBucketLifecycleRequest getBucketLifecycleRequest =new GetBucketLifecycleRequest(bucket);cosXmlService.getBucketLifecycleAsync(getBucketLifecycleRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketLifecycleResult getBucketLifecycleResult =(GetBucketLifecycleResult) 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";DeleteBucketLifecycleRequest deleteBucketLifecycleRequest =new DeleteBucketLifecycleRequest(bucket);cosXmlService.deleteBucketLifecycleAsync(deleteBucketLifecycleRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {DeleteBucketLifecycleResult deleteBucketLifecycleResult =(DeleteBucketLifecycleResult) 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();}}});
本页内容是否解决了您的问题?