Custom Domain

Last updated: 2023-09-13 15:07:31

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

For parameters and method description of all APIs in the SDK, see SDK API Reference.

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/bucket
req.bucket = @"examplebucket-1250000000";

QCloudDomainConfiguration *config = [QCloudDomainConfiguration new];
QCloudDomainRule *rule = [QCloudDomainRule new];

// Origin server status. Valid values: QCloudDomainStatueEnabled; QCloudDomainStatueDisabled
rule.status = QCloudDomainStatueEnabled;
// Domain information
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 complete
rule.replace = QCloudCOSDomainReplaceTypeTxt;
rule.type = QCloudCOSDomainTypeRest;

// Array of rule description sets
config.rules = @[rule];

// Domain configuration rule
req.domain = config;

[req setFinishBlock:^(id outputObject, NSError *error) {
// outputObject contains all response HTTP headers
NSDictionary* info = (NSDictionary *) outputObject;

}];
[[QCloudCOSXMLService defaultCOSXML]PutBucketDomain:req];
Note
For the complete sample, go to GitHub.
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/bucket
req.bucket = "examplebucket-1250000000";

let config = QCloudDomainConfiguration.init();
let rule = QCloudDomainRule.init();
// Indicate whether the rule is enabled. Valid values: .enabled; .disabled
rule.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 complete
rule.replace = .txt;
rule.type = .rest;

// Array of rule description sets
config.rules = [rule];

// Domain configuration rule
req.domain = config;
req.finishBlock = {(result,error) in
if let result = result {
// The result contains the response header information
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().putBucketDomain(req);
Note
For the complete sample, go to GitHub.

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/bucket
getReq.bucket = @"examplebucket-1250000000";

[getReq setFinishBlock:^(QCloudDomainConfiguration * _Nonnull result,
NSError * _Nonnull error) {
// Array of rule description sets
NSArray *rules = result.rules;
}];
[[QCloudCOSXMLService defaultCOSXML]GetBucketDomain:getReq];
Note
For the complete sample, go to GitHub.
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/bucket
req.bucket = "examplebucket-1250000000";

req.finishBlock = {(result,error) in
if let result = result {
// result contains origin server information
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getBucketDomain(req);
Note
For the complete sample, go to GitHub.

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