简介
本文档提供关于跨地域复制的 API 概览以及 SDK 示例代码。
API | 操作名 | 操作描述 |
设置跨地域复制 | 设置存储桶的跨地域复制规则 | |
查询跨地域复制 | 查询存储桶的跨地域复制规则 | |
删除跨地域复制 | 删除存储桶的跨地域复制规则 |
SDK API 参考
设置跨地域复制
功能说明
设置指定存储桶的跨地域复制规则。
示例代码
Objective-C
QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 说明所有跨地域配置信息QCloudBucketReplicationConfiguation* replConfiguration =[[QCloudBucketReplicationConfiguation alloc] init];// 发起者身份标示replConfiguration.role = @"qcs::cam::uin/100000000001:uin/100000000001";// 具体配置信息QCloudBucketReplicationRule* rule = [[QCloudBucketReplicationRule alloc] init];// 用来标注具体 Rule 的名称rule.identifier = @"identifier";rule.status = QCloudCOSXMLStatusEnabled;// 资源标识符QCloudBucketReplicationDestination* destination = [[QCloudBucketReplicationDestination alloc] init];NSString* destinationBucket = @"destinationbucket-1250000000";// 目标存储桶所在地域NSString* region = @"ap-beijing";destination.bucket = [NSString stringWithFormat:@"qcs::cos:%@::%@",region,destinationBucket];// 目标存储桶信息rule.destination = destination;// 前缀匹配策略,不可重叠,重叠返回错误。前缀匹配根目录为空rule.prefix = @"prefix1";replConfiguration.rule = @[rule];request.configuation = replConfiguration;[request setFinishBlock:^(id outputObject, NSError* error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketRelication:request];
说明
Swift
let putBucketReplication = QCloudPutBucketReplicationRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketputBucketReplication.bucket = "examplebucket-1250000000";// 说明所有跨地域配置信息let config = QCloudBucketReplicationConfiguation.init();config.role = "qcs::cam::uin/100000000001:uin/100000000001";// 发起者身份标示let rule = QCloudBucketReplicationRule.init();// 用来标注具体 Rule 的名称rule.identifier = "rule1";// 规则开启状态,可选 .enabled, .disabledrule.status = .enabled;// 目标存储桶信息let destination = QCloudBucketReplicationDestination.init();let destinationBucket = "destinationbucket-1250000000";let region = "ap-beijing";destination.bucket = "qcs::cos:\\(region)::\\(destinationBucket)";rule.destination = destination;// 前缀匹配策略,不可重叠,重叠返回错误。前缀匹配根目录为空rule.prefix = "dir/";config.rule = [rule];putBucketReplication.configuation = config;putBucketReplication.finishBlock = {(result,error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketRelication(putBucketReplication);
说明
查询跨地域复制
功能说明
查询指定存储桶的跨地域复制规则。
示例代码
Objective-C
QCloudGetBucketReplicationRequest* request = [[QCloudGetBucketReplicationRequest alloc] init];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(QCloudBucketReplicationConfiguation* result,NSError* error) {// 具体配置信息,最多支持 1000 个,所有策略只能指向一个目标存储桶NSArray *rules = result.rule;}];[[QCloudCOSXMLService defaultCOSXML] GetBucketReplication:request];
说明
Swift
let getBucketReplication = QCloudGetBucketReplicationRequest.init();getBucketReplication.bucket = "examplebucket-1250000000";getBucketReplication.setFinish { (config, error) inif let config = config {// 配置信息列表let rule = config.rule} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucketReplication(getBucketReplication);
说明
删除跨地域复制
功能说明
删除指定存储桶的跨地域复制规则。
示例代码
Objective-C
QCloudDeleteBucketReplicationRequest* request =[[QCloudDeleteBucketReplicationRequest alloc] init];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(id outputObject, NSError* error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteBucketReplication:request];
说明
Swift
let deleteBucketReplication = QCloudDeleteBucketReplicationRequest.init();deleteBucketReplication.bucket = "examplebucket-1250000000";deleteBucketReplication.finishBlock = {(result,error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteBucketReplication(deleteBucketReplication);
说明