Custom Domain

Last updated: 2020-08-18 11:02:43

    Overview

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

    API Operation Name 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 bucket

    SDK API Reference

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

    Setting a Custom Endpoint

    Feature description

    This API is used to configure a custom endpoint for a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    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;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           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 making requests using this API.

    Status Code Description
    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 endpoint is a domain name without ICP filing in the Chinese mainland.

    Querying a Custom Endpoint

    Feature description

    This API is used to query the custom endpoint of a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    GetBucketDomainRequest getBucketDomainRequest =
            new GetBucketDomainRequest(bucket);
    cosXmlService.getBucketDomainAsync(getBucketDomainRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            GetBucketDomainResult getBucketTaggingResult =
                    (GetBucketDomainResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           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

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help