use of com.qcloud.cos.COSClient in project cos-java-sdk-v5 by tencentyun.
the class BucketRefererDemo method createCosClient.
public static void createCosClient() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKID********************************", "********************************");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
// 3 生成cos客户端
cosClient = new COSClient(cred, clientConfig);
}
use of com.qcloud.cos.COSClient in project cos-java-sdk-v5 by tencentyun.
the class BucketReplicationDemo method createCOSClient.
public static void createCOSClient() {
COSCredentials cred = new BasicCOSCredentials("AKID********************************", "********************************");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
// 3 生成cos客户端
cosClient = new COSClient(cred, clientConfig);
}
use of com.qcloud.cos.COSClient in project cos-java-sdk-v5 by tencentyun.
the class BucketTaggingDemo method SetGetDeleteBucketTagging.
public static void SetGetDeleteBucketTagging() {
// 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";
List<TagSet> tagSetList = new LinkedList<TagSet>();
TagSet tagSet = new TagSet();
tagSet.setTag("age", "18");
tagSet.setTag("name", "xiaoming");
tagSetList.add(tagSet);
BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration();
bucketTaggingConfiguration.setTagSets(tagSetList);
SetBucketTaggingConfigurationRequest setBucketTaggingConfigurationRequest = new SetBucketTaggingConfigurationRequest(bucketName, bucketTaggingConfiguration);
cosclient.setBucketTaggingConfiguration(setBucketTaggingConfigurationRequest);
BucketTaggingConfiguration bucketTaggingConfiguration1 = cosclient.getBucketTaggingConfiguration(bucketName);
cosclient.deleteBucketTaggingConfiguration(bucketName);
}
use of com.qcloud.cos.COSClient in project cos-java-sdk-v5 by tencentyun.
the class BucketTaggingDemo method SetTagWhilePutObject.
public static void SetTagWhilePutObject() {
// 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-shanghai"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "testTag";
InputStream is = new ByteArrayInputStream(new byte[] { 'd', 'a', 't', 'a' });
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("x-cos-tagging", "level=info");
cosclient.putObject(bucketName, key, is, objectMetadata);
}
use of com.qcloud.cos.COSClient in project cos-java-sdk-v5 by tencentyun.
the class BucketWebsiteDemo method SetGetDeleteWebisteDemo.
public static void SetGetDeleteWebisteDemo() {
// 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";
// 设置bucket website
BucketWebsiteConfiguration bucketWebsiteConfiguration = new BucketWebsiteConfiguration();
// 索引文件
bucketWebsiteConfiguration.setIndexDocumentSuffix("index.html");
// 路由规则
List<RoutingRule> routingRuleList = new ArrayList<RoutingRule>();
RoutingRule routingRule = new RoutingRule();
RoutingRuleCondition routingRuleCondition = new RoutingRuleCondition();
routingRuleCondition.setHttpErrorCodeReturnedEquals("404");
routingRule.setCondition(routingRuleCondition);
RedirectRule redirectRule = new RedirectRule();
redirectRule.setProtocol("https");
redirectRule.setReplaceKeyPrefixWith("404.html");
routingRule.setRedirect(redirectRule);
routingRuleList.add(routingRule);
bucketWebsiteConfiguration.setRoutingRules(routingRuleList);
cosclient.setBucketWebsiteConfiguration(bucketName, bucketWebsiteConfiguration);
// 获取bucket website
BucketWebsiteConfiguration bucketWebsiteConfiguration1 = cosclient.getBucketWebsiteConfiguration(bucketName);
// 删除bucket website
cosclient.deleteBucketWebsiteConfiguration(bucketName);
}
Aggregations