Feature Overview
This document provides an overview of APIs and SDK code samples for custom domains.
API | Operation | Description |
PUT Bucket domain | Setting a Custom Endpoint | Sets a custom endpoint for a bucket |
GET Bucket domain | Querying a custom endpoint | Queries the custom endpoint of a bucket |
SDK API References
Setting a Custom Endpoint
Note
This API is used to configure a custom endpoint for a bucket.
Sample code
Objective-C
QCloudPutBucketDomainRequest *req = [QCloudPutBucketDomainRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketreq.bucket = @"examplebucket-1250000000";QCloudDomainConfiguration *config = [QCloudDomainConfiguration new];QCloudDomainRule *rule = [QCloudDomainRule new];// Origin server status. Valid values: QCloudDomainStatueEnabled; QCloudDomainStatueDisabledrule.status = QCloudDomainStatueEnabled;// Domain informationrule.name = @"www.baidu.com";// Replace the existing configuration. If CNAME/TXT is specified as a valid value, the new configuration won’t be delivered until verification of endpoint ownership is completerule.replace = QCloudCOSDomainReplaceTypeTxt;rule.type = QCloudCOSDomainTypeRest;// Array of rule description setsconfig.rules = @[rule];// Domain configuration rulereq.domain = config;[req setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains all response HTTP headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML]PutBucketDomain:req];
Note
Swift
let req = QCloudPutBucketDomainRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketreq.bucket = "examplebucket-1250000000";let config = QCloudDomainConfiguration.init();let rule = QCloudDomainRule.init();// Indicate whether the rule is enabled. Valid values: .enabled; .disabledrule.status = .enabled;rule.name = "www.baidu.com";// Replace the existing configuration. If CNAME/TXT is specified as a valid value, the new configuration won’t be delivered until verification of endpoint ownership is completerule.replace = .txt;rule.type = .rest;// Array of rule description setsconfig.rules = [rule];// Domain configuration rulereq.domain = config;req.finishBlock = {(result,error) inif let result = result {// The result contains the response header information} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketDomain(req);
Note
Error codes
The following describes some common errors that may occur when making requests using this API.
Status code | Note |
HTTP 409 Conflict | The endpoint record already exists, and forced overwrite is not specified in the request; OR the endpoint record does not exist, and forced overwrite is specified in the request |
HTTP 451 Unavailable For Legal Reasons | The domain does not have an ICP filing in the Chinese mainland |
Querying a custom endpoint
Note
This API is used to query the custom endpoint of a bucket.
Sample code
Objective-C
QCloudGetBucketDomainRequest *getReq = [QCloudGetBucketDomainRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketgetReq.bucket = @"examplebucket-1250000000";[getReq setFinishBlock:^(QCloudDomainConfiguration * _Nonnull result,NSError * _Nonnull error) {// Array of rule description setsNSArray *rules = result.rules;}];[[QCloudCOSXMLService defaultCOSXML]GetBucketDomain:getReq];
Note
Swift
let req = QCloudGetBucketDomainRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucketreq.bucket = "examplebucket-1250000000";req.finishBlock = {(result,error) inif let result = result {// result contains origin server information} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucketDomain(req);
Note
Response parameter description
Parameter name | Description | Local Disk Types |
x-cos-domain-txt-verification | Domain verification information, this field is an MD5 checksum value, the original string format is: cos[Region][BucketName-APPID][BucketCreateTime], where Region is the location of the storage bucket, and BucketCreateTime is the storage bucket's GMT creation time. | String |