tencent cloud

Setting Access Domain Names (CDN/Global Acceleration)
Last updated: 2024-06-25 10:53:13
Setting Access Domain Names (CDN/Global Acceleration)
Last updated: 2024-06-25 10:53:13

Overview

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

SDK API References

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

Default CDN acceleration domain name

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

Sample code

// The bucket region can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket/. For more information about regions, see https://www.tencentcloud.com/document/product/436/6224.
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

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

Sample code

// The bucket region can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket/. For more information about regions, see https://www.tencentcloud.com/document/product/436/6224.
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.

Sample code

// The bucket region can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket/. For more information about regions, see https://www.tencentcloud.com/document/product/436/6224.
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.

Sample code

// The bucket region can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket/. For more information about regions, see https://www.tencentcloud.com/document/product/436/6224.
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?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback