tencent cloud

All product documents
Cloud Object Storage
Adding Domain Names
Last updated: 2024-06-25 10:53:13
Adding Domain Names
Last updated: 2024-06-25 10:53:13

Overview

This document provides an overview of APIs and SDK code samples for custom domains.
API
Operation
Description
Setting a custom domain
Sets a custom domain for a bucket
Querying a custom endpoint
Queries the custom endpoint of a bucket
Deleting a custom domain
Deletes the custom domain configuration of a bucket

SDK API References

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

Setting Custom Domains

Feature description

This API is used to set a custom domain for a bucket.

Sample code

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
String bucket = "examplebucket-1250000000";
PutBucketDomainRequest putBucketDomainRequest =
new PutBucketDomainRequest(bucket);
DomainConfiguration.DomainRule domainRule = new DomainConfiguration.DomainRule(
DomainConfiguration.STATUS_ENABLED,
"www.example.com",
DomainConfiguration.TYPE_REST
);
domainRule.forcedReplacement = DomainConfiguration.REPLACE_CNAME;
putBucketDomainRequest.addDomainRule(domainRule);

cosXmlService.putBucketDomainAsync(putBucketDomainRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
PutBucketDomainResult putBucketDomainResult =
(PutBucketDomainResult) result;
}

// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:
For more samples, please visit GitHub.

Error codes

The following describes some common errors that may occur when you call this API:
Status Code
Description
HTTP 409 Conflict
The domain record already exists, and forced overwrite is not specified in the request; OR the domain 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 Domain

Feature description

This API is used to query the custom domain set for a bucket.

Sample code

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
String bucket = "examplebucket-1250000000";
GetBucketDomainRequest getBucketDomainRequest =
new GetBucketDomainRequest(bucket);
cosXmlService.getBucketDomainAsync(getBucketDomainRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
GetBucketDomainResult getBucketTaggingResult =
(GetBucketDomainResult) result;
}

// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:
For more samples, please visit GitHub.

Response parameters

Parameter
Description
API Type
x-cos-domain-txt-verification
Endpoint verification information. This field is an MD5 checksum of a character string in the format: cos[Region][BucketName-APPID][BucketCreateTime], where `Region` is the bucket region and `BucketCreateTime` is the time the bucket was created in GMT format
String


Deleting Custom Domains

Feature description

This API is used to delete the custom domain set for a bucket.
Note:
The COS Android SDK version should not be earlier than v5.9.8.

Sample code

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
String bucket = "examplebucket-1250000000";
DeleteBucketDomainRequest deleteBucketDomainRequest =
new DeleteBucketDomainRequest(bucket);
cosXmlService.deleteBucketDomainAsync(deleteBucketDomainRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
// For detailed fields, see the API documentation or SDK source code.
DeleteBucketDomainResult deleteBucketDomainResult =
(DeleteBucketDomainResult) result;
}
// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:
For more samples, please visit GitHub.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support