Feature Overview
This document provides an overview of APIs and SDK code samples for custom domains.
API | Operation | Description |
Setting a Custom Endpoint | Sets a custom endpoint for a bucket | |
Querying a custom endpoint | Queries the custom endpoint of a bucket | |
Deleting custom domain name | Deletes the custom domain configuration 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
// Bucket name in the format ofBucketName-APPID(APPIDis 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() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutBucketDomainResult putBucketDomainResult =(PutBucketDomainResult) result;}// If you are using Kotlin to call, please note that the exception in the callback method is nullable, otherwise the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? and the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
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
// Bucket name in the format ofBucketName-APPID(APPIDis 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() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketDomainResult getBucketTaggingResult =(GetBucketDomainResult) result;}// If you are using Kotlin to call, please note that the exception in the callback method is nullable, otherwise the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? and the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
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 |
Deleting custom domain name
Note
This API is used to delete the custom domain set for a bucket.
Note
The COS Android SDK version must be v5.9.8 or later.
Sample code
// Bucket name in the format ofBucketName-APPID(APPIDis 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() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {// For detailed fields, please refer to the API documentation or SDK source code.DeleteBucketDomainResult deleteBucketDomainResult =(DeleteBucketDomainResult) result;}// If you are using Kotlin to call, please note that the exception in the callback method is nullable, otherwise the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? and the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Note