tencent cloud

masukan

Adding Domain Names

Terakhir diperbarui: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.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

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

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24