API | 操作名 | 操作描述 |
设置生命周期 | 设置存储桶的生命周期管理的配置 | |
查询生命周期 | 查询存储桶生命周期管理的配置 | |
删除生命周期 | 删除存储桶生命周期管理的配置 |
public void setBucketLifecycleConfiguration(String bucketName, BucketLifecycleConfiguration bucketLifecycleConfiguration)throws CosClientException, CosServiceException;
List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();// 规则1 30天后删除路径以 hongkong_movie/ 为开始的文件BucketLifecycleConfiguration.Rule deletePrefixRule = new BucketLifecycleConfiguration.Rule();deletePrefixRule.setId("delete prefix xxxy after 30 days");deletePrefixRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("hongkong_movie/")));// 文件上传或者变更后, 30天后删除deletePrefixRule.setExpirationInDays(30);// 设置规则为生效状态deletePrefixRule.setStatus(BucketLifecycleConfiguration.ENABLED);// 规则2 20天后沉降到低频,一年后删除BucketLifecycleConfiguration.Rule standardIaRule = new BucketLifecycleConfiguration.Rule();standardIaRule.setId("standard_ia transition");standardIaRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("standard_ia/")));List<BucketLifecycleConfiguration.Transition> standardIaTransitions = new ArrayList<BucketLifecycleConfiguration.Transition>();BucketLifecycleConfiguration.Transition standardTransition = new BucketLifecycleConfiguration.Transition();standardTransition.setDays(20);standardTransition.setStorageClass(StorageClass.Standard_IA.toString());standardIaTransitions.add(standardTransition);standardIaRule.setTransitions(standardIaTransitions);standardIaRule.setStatus(BucketLifecycleConfiguration.ENABLED);standardIaRule.setExpirationInDays(365);// 将两条规则添加到策略集合中rules.add(deletePrefixRule);rules.add(standardIaRule);// 生成 bucketLifecycleConfigurationBucketLifecycleConfiguration bucketLifecycleConfiguration =new BucketLifecycleConfiguration();bucketLifecycleConfiguration.setRules(rules);// 存储桶的命名格式为 BucketName-APPIDString bucketName = "examplebucket-1250000000";SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest =new SetBucketLifecycleConfigurationRequest(bucketName, bucketLifecycleConfiguration);// 设置生命周期cosClient.setBucketLifecycleConfiguration(setBucketLifecycleConfigurationRequest);
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
bucketLifecycleConfiguration | 生命周期配置 | BucketLifecycleConfiguration |
public BucketLifecycleConfiguration getBucketLifecycleConfiguration(String bucketName)throws CosClientException, CosServiceException;
// 存储桶的命名格式为 BucketName-APPID ,此处填写的存储桶名称必须为此格式String bucketName = "examplebucket-1250000000";BucketLifecycleConfiguration queryLifeCycleRet =cosClient.getBucketLifecycleConfiguration(bucketName);List<BucketLifecycleConfiguration.Rule> ruleLists = queryLifeCycleRet.getRules();
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
public void deleteBucketLifecycleConfiguration(String bucketName)throws CosClientException, CosServiceException;
//存储桶的命名格式为 BucketName-APPIDString bucketName = "examplebucket-1250000000";cosClient.deleteBucketLifecycleConfiguration(bucketName);
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
本页内容是否解决了您的问题?