use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class BucketDemo method DeleteBucketDemo.
// 删除bucket, 只用于空bucket, 含有数据的bucket需要在删除前清空删除。
public static void DeleteBucketDemo() {
// 1 初始化用户身份信息(appid, 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-beijing-1"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名称, 需包含appid
String bucketName = "publicreadbucket-1251668577";
// 删除bucket
cosclient.deleteBucket(bucketName);
// 关闭客户端
cosclient.shutdown();
}
use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class BucketPolicyDemo method SetGetBucketPolicy.
public static void SetGetBucketPolicy() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("SECRET_ID", "SECRET_KEY");
// 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 = "examplebucket-1250000000";
String bucketPolicyStr = "{" + " \"Statement\": [" + " {" + " \"Principal\": {" + " \"qcs\": [" + " \"qcs::cam::uin/100000000001:uin/100000000011\"" + " ]" + " }," + " \"Effect\": \"deny\"," + " \"Action\": [" + " \"name/cos:GetObject\"" + " ]," + " \"Resource\": [" + " \"qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/test.txt\"" + " ]" + " }" + " ]," + " \"version\": \"2.0\"" + "}";
cosclient.setBucketPolicy(bucketName, bucketPolicyStr);
BucketPolicy bucketPolicy = cosclient.getBucketPolicy(bucketName);
System.out.println(bucketPolicy.getPolicyText());
}
use of com.qcloud.cos.auth.COSCredentials 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.auth.COSCredentials 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.auth.COSCredentials 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);
}
Aggregations