tencent cloud

Feedback

Setting Access Domain Names (CDN/Global Acceleration)

Last updated: 2022-05-09 14:28:43

    Overview

    This document describes how to request the COS service by using a non-default domain name.

    Default CDN acceleration domain name

    Feature description

    After enabling a default CDN acceleration domain name for a bucket through the COS console, you can set the domain name in the SDK code for acceleration.
    For more information, see Enabling Default CDN Acceleration Domain Names.

    Method prototype

    void com.qcloud.cos.ClientConfig.setEndPointSuffix(String endPointSuffix)
    

    Sample request

    // 1. Use a CDN acceleration domain. COS verification information does not need to be sent.
    COSCredentials cred = new AnonymousCOSCredentials();
    // 2. Set the region abbreviation for the bucket. For abbreviations of COS regions, visit https://www.tencentcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing"));
    // HTTPS is recommended.
    clientConfig.setHttpProtocol(HttpProtocol.https);
    // 3. Set the suffix for the default CDN acceleration domain.
    String cdnSuffix = "file.myqcloud.com";
    clientConfig.setEndPointSuffix(cdnSuffix);
    // 4. Generate a COS client
    COSClient cosclient = new COSClient(cred, clientConfig);
    

    Parameter description

    Parameter Description Type
    endPointSuffix Set the domain suffix to use the CDN acceleration domain name String

    Custom CDN acceleration domain name

    Feature description

    After setting a custom CDN acceleration domain name for a bucket through the COS console, you can set the domain name in the SDK code for acceleration. For more information, see Enabling Custom Accelerated Domain Name.

    Method prototype

    void com.qcloud.cos.ClientConfig.setEndpointBuilder(EndpointBuilder endpointBuilder)
    

    Sample request

    // 1. Use a CDN acceleration domain. COS verification information does not need to be sent.
    COSCredentials cred = new AnonymousCOSCredentials();
    // 2. Set the region abbreviation for the bucket. For abbreviations of COS regions, visit https://www.tencentcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing"));
    // HTTPS is recommended, which requires the custom domain to have the relevant HTTPS certificate.
    clientConfig.setHttpProtocol(HttpProtocol.https);
    // 3. Set the custom CDN domain name.
    // The `get service` request will use this domain, which is fixed.
    String serviceApiEndpoint = "service.cos.myqcloud.com";
    String cdnEndpoint = "xxx.xxx.com";
    UserSpecifiedEndpointBuilder endPointBuilder = new UserSpecifiedEndpointBuilder(cdnEndpoint, serviceApiEndpoint);
    clientConfig.setEndpointBuilder(endPointBuilder);
    // 4. Generate a COS client
    COSClient cosclient = new COSClient(cred, clientConfig);
    

    Parameter description

    Parameter Description Type
    endPointerBuilder Constructs the custom CDN acceleration domain. UserSpecifiedEndpointBuilder

    UserSpecifiedEndpointBuilder description:

    Parameter Description Type
    generalApiEndpoint Custom CDN acceleration domain name String
    getServiceApiEndpoint Fixed to service.cos.myqcloud.com String

    Custom origin server domain name

    Feature description

    After setting a custom origin server domain for a bucket through the COS console, you can set the domain name in the SDK code to access COS resources. For more information, see Enabling Custom Origin Server Domains.

    Method prototype

    void com.qcloud.cos.ClientConfig.setEndpointBuilder(EndpointBuilder endpointBuilder)
    

    Sample request

    // 1. Initialize user authentication information (secretId, secretKey).
    // You can log in to the CAM console to view and manage `secretId` and `secretKey`.
    String secretId = "SECRETID";
    String secretKey = "SECRETKEY";
    COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
    // 2. Set the region abbreviation for the bucket. For abbreviations of COS regions, visit https://www.tencentcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing"));
    // HTTPS is recommended.
    clientConfig.setHttpProtocol(HttpProtocol.https);
    // 3. Set the custom domain name.
    // The get service request will use this domain, which is fixed.
    String serviceApiEndpoint = "service.cos.myqcloud.com";
    String userEndpoint = "xxx.xxx.com";
    UserSpecifiedEndpointBuilder endPointBuilder = new UserSpecifiedEndpointBuilder(userEndpoint, serviceApiEndpoint);
    clientConfig.setEndpointBuilder(endPointBuilder);
    // 4. Generate a COS client
    COSClient cosclient = new COSClient(cred, clientConfig);
    

    Parameter description

    Parameter Description Type
    endPointerBuilder Constructs the custom origin server domain. UserSpecifiedEndpointBuilder

    UserSpecifiedEndpointBuilder description:

    Parameter Description Type
    generalApiEndpoint Custom origin server domain String
    getServiceApiEndpoint Fixed to service.cos.myqcloud.com String

    Global acceleration domain name

    Feature description

    After enabling a global acceleration domain name for a bucket through the COS console, you can set the domain name in the SDK code for global acceleration. For more information, see Overview.

    Method prototype

    void com.qcloud.cos.ClientConfig.setEndPointSuffix(String endPointSuffix)
    

    Sample request

    // 1. Initialize user authentication information (`secretId`, `secretKey`).
    // You can log in to the CAM console to view and manage `secretId` and `secretKey`.
    String secretId = "SECRETID";
    String secretKey = "SECRETKEY";
    COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
    // 2. Set the region abbreviation for the bucket. For abbreviations of COS regions, visit https://www.tencentcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing"));
    // HTTPS is recommended.
    clientConfig.setHttpProtocol(HttpProtocol.https);
    // 3. Set the suffix for the global acceleration endpoint.
    String cosSuffix = "cos.accelerate.myqcloud.com";
    clientConfig.setEndPointSuffix(cosSuffix);
    // 4. Generate a COS client
    COSClient cosclient = new COSClient(cred, clientConfig);
    

    Parameter description

    Parameter Description Type
    endPointSuffix Set the domain suffix to use a global acceleration domain name. 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