简介
本文档提供关于生命周期的 API 概览以及 SDK 示例代码。
API | 操作名 | 操作描述 |
设置生命周期 | 设置存储桶的生命周期管理的配置 | |
查询生命周期 | 查询存储桶生命周期管理的配置 | |
删除生命周期 | 删除存储桶生命周期管理的配置 |
SDK API 参考
设置生命周期
功能说明
设置指定存储桶的生命周期配置信息。
示例代码
Objective-C
QCloudPutBucketLifecycleRequest* request = [QCloudPutBucketLifecycleRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";__block QCloudLifecycleConfiguration* lifecycleConfiguration =[[QCloudLifecycleConfiguration alloc] init];// 规则描述QCloudLifecycleRule* rule = [[QCloudLifecycleRule alloc] init];// 用于唯一地标识规则rule.identifier = @"identifier";// 指明规则是否启用,枚举值:Enabled,Disabledrule.status = QCloudLifecycleStatueEnabled;// Filter 用于描述规则影响的 Object 集合QCloudLifecycleRuleFilter* filter = [[QCloudLifecycleRuleFilter alloc] init];// 指定规则所适用的前缀。匹配前缀的对象受该规则影响,Prefix 最多只能有一个filter.prefix = @"prefix1";// Filter 用于描述规则影响的 Object 集合rule.filter = filter;// 规则转换属性,对象何时转换为 Standard_IA 或 ArchiveQCloudLifecycleTransition* transition = [[QCloudLifecycleTransition alloc] init];// 指明规则对应的动作在对象最后的修改日期过后多少天操作:transition.days = 100;// 指定 Object 转储到的目标存储类型,枚举值: STANDARD_IA,ARCHIVEtransition.storageClass = QCloudCOSStorageStandardIA;rule.transition = transition;request.lifeCycle = lifecycleConfiguration;// 生命周期配置request.lifeCycle.rules = @[rule];[request setFinishBlock:^(id outputObject, NSError* error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketLifecycle:request];
说明
Swift
let putBucketLifecycleReq = QCloudPutBucketLifecycleRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketputBucketLifecycleReq.bucket = "examplebucket-1250000000";let config = QCloudLifecycleConfiguration.init();// 规则描述let rule = QCloudLifecycleRule.init();// 用于唯一地标识规则rule.identifier = "swift";// 指明规则是否启用,枚举值:Enabled,Disabledrule.status = .enabled;// Filter 用于描述规则影响的 Object 集合let fileter = QCloudLifecycleRuleFilter.init();// 指定规则所适用的前缀。匹配前缀的对象受该规则影响,Prefix 最多只能有一个fileter.prefix = "0";// Filter 用于描述规则影响的 Object 集合rule.filter = fileter;// 规则转换属性,对象何时转换为 Standard_IA 或 Archivelet transition = QCloudLifecycleTransition.init();// 指明规则对应的动作在对象最后的修改日期过后多少天操作:transition.days = 100;// 指定 Object 转储到的目标存储类型,枚举值: STANDARD_IA,ARCHIVEtransition.storageClass = .standardIA;rule.transition = transition;putBucketLifecycleReq.lifeCycle = config;// 生命周期配置putBucketLifecycleReq.lifeCycle.rules = [rule];putBucketLifecycleReq.finishBlock = {(result,error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketLifecycle(putBucketLifecycleReq);
说明
查询生命周期
功能说明
查询存储桶的生命周期管理配置。
示例代码
Objective-C
QCloudGetBucketLifecycleRequest* request = [QCloudGetBucketLifecycleRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(QCloudLifecycleConfiguration* result,NSError* error) {// 可以从 result 中获取返回信息// result.rules 规则描述集合的数组}];[[QCloudCOSXMLService defaultCOSXML] GetBucketLifecycle:request];
说明
Swift
let getBucketLifeCycle = QCloudGetBucketLifecycleRequest.init();getBucketLifeCycle.bucket = "examplebucket-1250000000";getBucketLifeCycle.setFinish { (config, error) inif let config = config {// 生命周期规则let rules = config.rules} else {print(error!);}};QCloudCOSXMLService.defaultCOSXML().getBucketLifecycle(getBucketLifeCycle);
说明
删除生命周期
功能说明
删除存储桶生命周期管理的配置。
示例代码
Objective-C
QCloudDeleteBucketLifeCycleRequest* request =[[QCloudDeleteBucketLifeCycleRequest alloc ] init];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(QCloudLifecycleConfiguration* deleteResult, NSError* error) {// 返回删除结果}];[[QCloudCOSXMLService defaultCOSXML] DeleteBucketLifeCycle:request];
说明
Swift
let deleteBucketLifeCycle = QCloudDeleteBucketLifeCycleRequest.init();deleteBucketLifeCycle.bucket = "examplebucket-1250000000";deleteBucketLifeCycle.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}};QCloudCOSXMLService.defaultCOSXML().deleteBucketLifeCycle(deleteBucketLifeCycle);
说明