API | Operation | Description |
Setting lifecycle configuration | Sets lifecycle for a bucket | |
Querying a lifecycle configuration | Queries the lifecycle configuration of a bucket | |
Deleting a lifecycle configuration | Deletes the lifecycle configuration of a bucket |
QCloudPutBucketLifecycleRequest* request = [QCloudPutBucketLifecycleRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";__block QCloudLifecycleConfiguration* lifecycleConfiguration =[[QCloudLifecycleConfiguration alloc] init];// Rule descriptionQCloudLifecycleRule* rule = [[QCloudLifecycleRule alloc] init];// Unique rule IDrule.identifier = @"identifier";// Indicates whether the rule is enabled. Enumerated values: Enabled, Disabledrule.status = QCloudLifecycleStatueEnabled;// Describes the set of objects subject to the ruleQCloudLifecycleRuleFilter* filter = [[QCloudLifecycleRuleFilter alloc] init];// Specifies the prefix to which the rule applies. Objects that match the prefix are subject to the rule. You can specify at most one prefixfilter.prefix = @"prefix1";// Describes the set of objects subject to the rulerule.filter = filter;// Transition attribute of the rule, specifying when an object should transition to Standard_IA or ARCHIVE storage classQCloudLifecycleTransition* transition = [[QCloudLifecycleTransition alloc] init];// Specifies the number of days after which the object is last modified that the action in the rule will be performedtransition.days = 100;// Specifies the transitioned storage class of object. Enumerated values: Standard_IA, ARCHIVEtransition.storageClass = QCloudCOSStorageStandardIA;rule.transition = transition;request.lifeCycle = lifecycleConfiguration;// Lifecycle configurationrequest.lifeCycle.rules = @[rule];[request setFinishBlock:^(id outputObject, NSError* error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketLifecycle:request];
let putBucketLifecycleReq = QCloudPutBucketLifecycleRequest.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketputBucketLifecycleReq.bucket = "examplebucket-1250000000";let config = QCloudLifecycleConfiguration.init();// Rule descriptionlet rule = QCloudLifecycleRule.init();// Unique rule IDrule.identifier = "swift";// Indicates whether the rule is enabled. Enumerated values: Enabled, Disabledrule.status = .enabled;// Describes the set of objects subject to the rulelet fileter = QCloudLifecycleRuleFilter.init();// Specifies the prefix to which the rule applies. Objects that match the prefix are subject to the rule. You can specify at most one prefixfileter.prefix = "0";// Describes the set of objects subject to the rulerule.filter = fileter;// Transition attribute of the rule, specifying when an object should transition to Standard_IA or ARCHIVE storage classlet transition = QCloudLifecycleTransition.init();// Specifies the number of days after which the object is last modified that the action in the rule will be performedtransition.days = 100;// Specifies the transitioned storage class of object. Enumerated values: Standard_IA, ARCHIVEtransition.storageClass = .standardIA;rule.transition = transition;putBucketLifecycleReq.lifeCycle = config;// Lifecycle configurationputBucketLifecycleReq.lifeCycle.rules = [rule];putBucketLifecycleReq.finishBlock = {(result,error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketLifecycle(putBucketLifecycleReq);
QCloudGetBucketLifecycleRequest* request = [QCloudGetBucketLifecycleRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(QCloudLifecycleConfiguration* result,NSError* error) {// You can get the returned information from result// `result.rules` is the array of rule descriptions}];[[QCloudCOSXMLService defaultCOSXML] GetBucketLifecycle:request];
let getBucketLifeCycle = QCloudGetBucketLifecycleRequest.init();getBucketLifeCycle.bucket = "examplebucket-1250000000";getBucketLifeCycle.setFinish { (config, error) inif let config = config {// Lifecycle rulelet rules = config.rules} else {print(error!);}};QCloudCOSXMLService.defaultCOSXML().getBucketLifecycle(getBucketLifeCycle);
QCloudDeleteBucketLifeCycleRequest* request =[[QCloudDeleteBucketLifeCycleRequest alloc ] init];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(QCloudLifecycleConfiguration* deleteResult, NSError* error) {// Returns the deletion result}];[[QCloudCOSXMLService defaultCOSXML] DeleteBucketLifeCycle:request];
let deleteBucketLifeCycle = QCloudDeleteBucketLifeCycleRequest.init();deleteBucketLifeCycle.bucket = "examplebucket-1250000000";deleteBucketLifeCycle.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}};QCloudCOSXMLService.defaultCOSXML().deleteBucketLifeCycle(deleteBucketLifeCycle);
Was this page helpful?