Custom Domain

Last updated: 2020-03-20 09:28:12

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

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudPutBucketDomainRequest
  2. Call the PutBucketDomain method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudPutBucketDomainRequest *req = [QCloudPutBucketDomainRequest new];
    req.bucket = @"examplebucket-1250000000";
    QCloudDomainConfiguration *config = [QCloudDomainConfiguration new];
    QCloudDomainRule *rule = [QCloudDomainRule new];
    rule.status = QCloudDomainStatueEnabled;
    rule.name = @"www.baidu.com";
    rule.replace = QCloudCOSDomainReplaceTypeTxt;
    rule.type = QCloudCOSDomainTypeRest;
    config.rules = @[rule];
    req.domain  = config;
    [req setFinishBlock:^(id outputObject, NSError *error) {

    }];
      [[QCloudCOSXMLService defaultCOSXML]PutBucketDomain:req];

Swift code example:

let req = QCloudPutBucketDomainRequest.init();
req.bucket = "examplebucket-1250000000";

let config = QCloudDomainConfiguration.init();
let rule = QCloudDomainRule.init();
rule.status = .enabled;
rule.name = "www.baidu.com";
rule.replace = .txt;
rule.type = .rest;
config.rules = [rule];
req.domain = config;
req.finishBlock = {(result,error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }

}
QCloudCOSXMLService.defaultCOSXML().putBucketDomain(req);

Parameter description

QCloudPutBucketDomainRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Set the custom domain name Bucket in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
Domain Rules for domain name configuration QCloudDomainConfiguration * Yes

QCloudDomainConfiguration parameter description

Parameter name Description Type Required/Optional
Rules An array of rules that describe a collection NSArray < QCloudDomainRule * > * Yes

QCloudDomainRule parameter description

Parameter name Description Type Required/Optional
Name User's custom domain name. Valid values: letters, numbers, dots NSString * Yes
Status Domain name Activate / deactivate status, valid value ENABLED/DISABLED QCloudDomainStatue Yes
Type Bound real server type, valid value REST/WEBSITE QCloudCOSDomainType Yes
Replace Replace the existing configuration with a valid value of CNAME/TXT. Enter forcefully verifies the ownership of the domain name, and then deliver configures it. QCloudCOSDomainReplaceType Yes

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.

Query custom domain name

Function description

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

Method prototype

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudGetBucketDomainRequest
  2. Call the GetBucketDomain method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the result in the finishBlock of the callback.

Request Sample

QCloudGetBucketDomainRequest *getReq =  [QCloudGetBucketDomainRequest new];
getReq.bucket = @"examplebucket-1250000000";
[getReq setFinishBlock:^(QCloudDomainConfiguration * _Nonnull result, NSError * _Nonnull error) {

}];
[[QCloudCOSXMLService defaultCOSXML]GetBucketDomain:getReq];

Swift code example:

let req = QCloudGetBucketDomainRequest.init();
req.bucket = "examplebucket-1250000000";

req.finishBlock = {(result,error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
}
QCloudCOSXMLService.defaultCOSXML().getBucketDomain(req);

Parameter description

QCloudGetBucketTaggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Query the Bucket of the custom domain name in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
Domain Rules for domain name configuration QCloudDomainConfiguration * Yes

Return parameter description

QCloudDomainConfiguration parameter description

Parameter name Description Type
Rules An array of rules that describe a collection NSArray < QCloudDomainRule * > *

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.