Setting Access Domain Names

Last updated: 2020-08-26 11:01:39

    Overview

    This document describes how to request a COS service using a non-default COS endpoint.

    SDK API Reference

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

    Default CDN acceleration domain name

    For more information, see Enabling Default CDN Acceleration Domain Names.

    The sample code below shows how to access a COS service using a default CDN acceleration domain name.

    String region = "ap-beijing"; // Bucket region
    // Default CDN acceleration domain name of the bucket
    String cdnDomain = "examplebucket-1250000000.file.myqcloud.com";
    
    CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
            .isHttps(true)
            .setRegion(region)
            .setDebuggable(false)
            .setHostFormat(cdnDomain) // Modify the requested domain name
            .addHeader("Host", cdnDomain) // Modify the “Host” filed in the header
            .builder();
    
    // The credentialProvider class is not provided. Instead, you add parameters to the URL when downloading
    // for CDN permission verification
    CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig);

    Note:

    For more samples, please visit GitHub.

    Custom CDN acceleration domain name

    For more information, see Enabling Custom CDN Acceleration Domain Names.

    The sample code below shows how to access a COS service using a custom CDN acceleration domain name.

    String region = "ap-beijing"; // Bucket region
    String cdnCustomDomain = "exampledomain.com"; // Custom CDN acceleration domain name
    
    CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
            .isHttps(true)
            .setRegion(region)
            .setDebuggable(false)
            .setHostFormat(cdnCustomDomain) // Modify the requested domain name
            .addHeader("Host", cdnCustomDomain) // Modify the “Host” filed in the header
            .builder();
    // The credentialProvider class is not provided. Instead, you add parameters to the URL when downloading
    // for CDN permission verification
    CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig);

    Note:

    For more samples, please visit GitHub.

    Custom origin server domain name

    For more information, see Enabling Custom Origin Domain.

    The sample code below shows how to access a COS service using a custom origin server domain name.

    String region = "ap-beijing"; // Bucket region
    String customDomain = "exampledomain.com"; // Custom origin server domain name
    
    CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
            .isHttps(true)
            .setRegion(region)
            .setDebuggable(false)
            .setHostFormat(customDomain) // Modify the requested domain name
            .builder();
    
    CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,
            credentialProvider);

    Note:

    For more samples, please visit GitHub.

    Global acceleration endpoint

    For more information on global acceleration, see Overview.

    The sample code below shows how to access a COS service using a global acceleration endpoint.

    String region = "ap-beijing"; // Bucket region
    
    CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
            .isHttps(true)
            .setRegion(region)
            .setDebuggable(false)
            .setAccelerate(true) // Enable a global acceleration endpoint
            .builder();
    
    CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,
            credentialProvider);

    Note:

    For more samples, please visit GitHub.

    Was this page helpful?

    Was this page helpful?

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