com.branch.cos.demo.BucketDomainDemo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of branch_cos_api Show documentation
Show all versions of branch_cos_api Show documentation
branch java sdk for qcloud cos
package com.branch.cos.demo;
import com.branch.cos.COSClient;
import com.branch.cos.ClientConfig;
import com.branch.cos.auth.BasicCOSCredentials;
import com.branch.cos.auth.COSCredentials;
import com.branch.cos.model.BucketDomainConfiguration;
import com.branch.cos.model.DomainRule;
import com.branch.cos.region.Region;
public class BucketDomainDemo {
public static void SetGetBucketDomainDemo() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
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);
System.out.println(bucketDomainConfiguration1.getDomainTxtVerification());
}
public static void main(String[] args) {
SetGetBucketDomainDemo();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy