This document provides an overview of APIs and SDK code samples for custom domains.
API | Operation | Description |
---|---|---|
PUT Bucket domain | Setting a custom domain | Sets a custom domain for a bucket |
GET Bucket domain | Querying a custom endpoint | Queries the custom endpoint of a bucket |
DELETE Bucket domain | Deleting a custom domain | Deletes the custom domain configuration of a bucket |
For the parameters and method descriptions of all the APIs in the SDK, see SDK API Reference.
This API is used to set a custom domain for a bucket.
// 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.
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 |
This API is used to query the custom domain set for a bucket.
// 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.
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 |
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.
// 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.
Apakah halaman ini membantu?