Custom Domain

Last updated: 2020-03-20 09:32:19

PDF

Note

This document provides an overview of API for custom domain names and sample SDK code.

API Operation name pedagogical operation
PUT Bucket domain Set up a custom domain name Set Bucket's custom domain name information
GET Bucket domain Query custom domain name Query Bucket's custom domain name information

Set up a custom domain name

Function description

PUT Bucket domain is used to configure a custom domain name for Bucket.

Method prototype

public void setBucketDomainConfiguration(String bucketName, BucketDomainConfiguration configuration);
public void setBucketDomainConfiguration(SetBucketDomainConfigurationRequest setBucketDomainConfigurationRequest);

Request Sample

String bucketName = "examplebucket-1250000000";
BucketDomainConfiguration bucketDomainConfiguration = new BucketDomainConfiguration();
DomainRule domainRule = new DomainRule();
domainRule.setStatus(DomainRule.ENABLED);
domainRule.setType(DomainRule.REST);
domainRule.setName("qq.com");
domainRule.setForcedReplacement(DomainRule.CNAME);
bucketDomainConfiguration.getDomainRules().add(domainRule);
cosclient.setBucketDomainConfiguration(bucketName, bucketDomainConfiguration);
BucketDomainConfiguration bucketDomainConfiguration1 = cosclient.getBucketDomainConfiguration(bucketName);

Parameter description

Parameter name Description Type
SetBucketDomainConfigurationRequest Set Bucket custom domain name request SetBucketDomainConfigurationRequest

Request member description:

Request member Setting method Description Type
BucketName Constructor or set method Set the custom domain name Bucket in BucketName-APPID format. For more information, please see Naming convention String
Configuration Constructor or set method Bucket's custom domain name configuration BucketDomainConfiguration

BucketDomainConfiguration member description:

Parameter name Description Type
DomainRules Bucket's custom domain name configuration List DomainRules

DomainRule member description:

Parameter name Description Type
Name Custom Domain String
Status Domain name Activate status. Available values include ENABLED and DISABLED String
Type The type of real server bound. Available values include REST and WEBSITE. String
ForcedReplacement Forced overwrite of existing configurations. Available values include CNAME and TXT String

Return result description

  • Success: no return value.
  • Failure: if an error occurs (such as Identity verification failure), an exception CosClientException or CosServiceException is thrown. For more information, please see Exception Handling .

Returns the error code description

Some common special errors that may occur in this request are as follows:

Status Code Description
HTTP 409 Conflict The domain name record already exists and no mandatory overwrite is set in the request. Or the domain name record does not exist and a forced overwrite is set in the request
HTTP 451 Unavailable For Legal Reasons The domain name is a domain name within China, and there is no ICP filing.

Query custom domain name

Function description

GET Bucket domain is used to query Bucket's custom domain name information.

Method prototype

public BucketDomainConfiguration getBucketDomainConfiguration(String bucketName)
throws CosClientException, CosServiceException;

Request Sample

String bucketName = "examplebucket-1250000000";
BucketDomainConfiguration bucketDomainConfiguration1 = cosclient.getBucketDomainConfiguration(bucketName);
String domainTxtVerification = bucketDomainConfiguration1.getDomainTxtVerification()

Parameter description

Parameter name Description Type
BucketName Query the Bucket of the custom domain name in BucketName-APPID format. For more information, please see Naming convention String

Return result description

  • Success: return BucketDomainConfiguration, containing Bucket's custom domain name setting information.
  • Failure: if an error occurs (such as Identity verification failure), an exception CosClientException or CosServiceException is thrown. For more information, please see Exception Handling .

Return parameter description

Parameter name Description Type
DomainTxtVerification Domain name verification information. This field is a MD5 check value. The original string format is: cos[Region][BucketName-APPID][BucketCreateTime] Where Region is the region where Bucket is located, and BucketCreateTime is the creation time of Bucket GMT String