tencent cloud

Feedback

Customizing Domain Names

Last updated: 2022-01-23 14:33:34

    Overview

    This document provides an overview of APIs and SDK code samples related to custom domains.

    API Operation Description
    PUT Bucket domain Setting a custom domain Sets a custom domain for a bucket
    GET Bucket domain Querying a custom domain Queries the custom domain 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

    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.tencentcloud.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

    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.tencentcloud.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 Name Description 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
    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