API | Operation | Description |
Setting lifecycle configuration | Sets lifecycle management configuration for a bucket | |
Querying a lifecycle configuration | Queries the lifecycle management configuration of a bucket | |
Deleting lifecycle | Deletes the lifecycle management configuration of bucket |
public void setBucketLifecycleConfiguration(String bucketName, BucketLifecycleConfiguration bucketLifecycleConfiguration)throws CosClientException, CosServiceException;
List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();// Rule 1: delete files whose paths start with hongkong_movie/ after 30 daysBucketLifecycleConfiguration.Rule deletePrefixRule = new BucketLifecycleConfiguration.Rule();deletePrefixRule.setId("delete prefix xxxy after 30 days");deletePrefixRule.setFilter(new LifecycleFilter(new LifecyclePrefixPredicate("hongkong_movie/")));// Deleting files that have been uploaded or modified for 30 daysdeletePrefixRule.setExpirationInDays(30);// Setting rules to activedeletePrefixRule.setStatus(BucketLifecycleConfiguration.ENABLED);// Rule 2: put files into low frequency after 20 days and delete them after one yearBucketLifecycleConfiguration.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);// Adding two rules to the policy setrules.add(deletePrefixRule);rules.add(standardIaRule);// Generating bucketLifecycleConfigurationBucketLifecycleConfiguration bucketLifecycleConfiguration =new BucketLifecycleConfiguration();bucketLifecycleConfiguration.setRules(rules);// Bucket name in the format of BucketName-APPIDString bucketName = "examplebucket-1250000000";SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest =new SetBucketLifecycleConfigurationRequest(bucketName, bucketLifecycleConfiguration);// Configuring the lifecycle configurationcosClient.setBucketLifecycleConfiguration(setBucketLifecycleConfigurationRequest);
Parameter | Description | Type |
bucketName | String | |
bucketLifecycleConfiguration | Lifecycle configuration | BucketLifecycleConfiguration |
CosClientException
or CosServiceException
exception thrown. For more information, please see Troubleshooting.public BucketLifecycleConfiguration getBucketLifecycleConfiguration(String bucketName)throws CosClientException, CosServiceException;
// Entering the bucket name in the format of BucketName-APPID.String bucketName = "examplebucket-1250000000";BucketLifecycleConfiguration queryLifeCycleRet =cosClient.getBucketLifecycleConfiguration(bucketName);List<BucketLifecycleConfiguration.Rule> ruleLists = queryLifeCycleRet.getRules();
Parameter | Description | Type |
bucketName | String |
BucketLifecycleConfiguration
class is returned, which contains the lifecycle rule of the bucket.CosClientException
or CosServiceException
exception thrown. For more information, please see Troubleshooting.public void deleteBucketLifecycleConfiguration(String bucketName)throws CosClientException, CosServiceException;
// Bucket name in the format of BucketName-APPIDString bucketName = "examplebucket-1250000000";cosClient.deleteBucketLifecycleConfiguration(bucketName);
Parameter | Description | Type |
bucketName | String |
CosClientException
or CosServiceException
exception thrown. For more information, please see Troubleshooting.
Was this page helpful?