API | 操作名 | 操作描述 |
设置跨域配置 | 设置存储桶的跨域名访问权限 | |
查询跨域配置 | 查询存储桶的跨域名访问配置信息 | |
删除跨域配置 | 删除存储桶的跨域名访问配置信息 |
QCloudPutBucketCORSRequest* putCORS = [QCloudPutBucketCORSRequest new];QCloudCORSConfiguration* cors = [QCloudCORSConfiguration new];QCloudCORSRule* rule = [QCloudCORSRule new];// 配置规则 IDrule.identifier = @"rule1";// 跨域请求可以使用的 HTTP 请求头部,支持通配符 *rule.allowedHeader = @[@"origin",@"host",@"accept",@"content-type",@"authorization"];rule.exposeHeader = @"ETag";// 跨域请求允许的 HTTP 操作,例如:GET,PUT,HEAD,POST,DELETErule.allowedMethod = @[@"GET",@"PUT",@"POST", @"DELETE", @"HEAD"];// 跨域请求得到结果的有效期rule.maxAgeSeconds = 3600;// 允许的访问来源,支持通配符 *,格式为:协议://域名[:端口]rule.allowedOrigin = @"http://cloud.tencent.com";cors.rules = @[rule];putCORS.corsConfiguration = cors;// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketputCORS.bucket = @"examplebucket-1250000000";[putCORS setFinishBlock:^(id outputObject, NSError *error) {// 可以从 outputObject 中获取服务器返回的 header 信息NSDictionary * result = (NSDictionary *)outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketCORS:putCORS];
let putBucketCorsReq = QCloudPutBucketCORSRequest.init();let corsConfig = QCloudCORSConfiguration.init();let rule = QCloudCORSRule.init();// 配置规则的 IDrule.identifier = "rule1";// 跨域请求可以使用的 HTTP 请求头部,支持通配符 *rule.allowedHeader = ["origin","host","accept","content-type","authorization"];rule.exposeHeader = "Etag";// 跨域请求允许的 HTTP 操作,例如:GET,PUT,HEAD,POST,DELETErule.allowedMethod = ["GET","PUT","POST", "DELETE", "HEAD"];// 跨域请求得到结果的有效期rule.maxAgeSeconds = 3600;// 允许的访问来源,支持通配符 *,格式为:协议://域名[:端口]rule.allowedOrigin = "*";corsConfig.rules = [rule];putBucketCorsReq.corsConfiguration = corsConfig;// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketputBucketCorsReq.bucket = "examplebucket-1250000000";putBucketCorsReq.finishBlock = {(result,error) inif let result = result {// 可以从 result 中获取服务器返回的 header 信息} else {print(error!)}}QCloudCOSXMLService.defaultCOSXML().putBucketCORS(putBucketCorsReq);
QCloudGetBucketCORSRequest* corsReqeust = [QCloudGetBucketCORSRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketcorsReqeust.bucket = @"examplebucket-1250000000";[corsReqeust setFinishBlock:^(QCloudCORSConfiguration * _Nonnull result,NSError * _Nonnull error) {// 跨域规则列表NSArray<QCloudCORSRule*> *rules = result.rules;}];[[QCloudCOSXMLService defaultCOSXML] GetBucketCORS:corsReqeust];
let getBucketCorsRes = QCloudGetBucketCORSRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetBucketCorsRes.bucket = "examplebucket-1250000000";getBucketCorsRes.setFinish { (corsConfig, error) inif let corsConfig = corsConfig {// 跨域规则列表let rules = corsConfig.rules} else {print(error!)}}QCloudCOSXMLService.defaultCOSXML().getBucketCORS(getBucketCorsRes);
QCloudDeleteBucketCORSRequest* deleteCORS = [QCloudDeleteBucketCORSRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketdeleteCORS.bucket = @"examplebucket-1250000000";[deleteCORS setFinishBlock:^(id outputObject, NSError *error) {// 可以从 outputObject 中获取服务器返回的 header 信息NSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteBucketCORS:deleteCORS];
let deleteBucketCorsRequest = QCloudDeleteBucketCORSRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketdeleteBucketCorsRequest.bucket = "examplebucket-1250000000";deleteBucketCorsRequest.finishBlock = {(result,error) inif let result = result {// 可以从 result 中获取服务器返回的 header 信息} else {print(error!)}}QCloudCOSXMLService.defaultCOSXML().deleteBucketCORS(deleteBucketCorsRequest);
本页内容是否解决了您的问题?