use of com.qcloud.cos.model.CreateBucketRequest in project jeesuite-libs by vakinge.
the class QcloudProvider method createBucket.
@Override
public void createBucket(String bucketName, boolean isPrivate) {
bucketName = buildBucketName(bucketName);
if (cosclient.doesBucketExist(bucketName)) {
throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
}
CreateBucketRequest request = new CreateBucketRequest(bucketName);
if (isPrivate) {
request.setCannedAcl(CannedAccessControlList.Private);
} else {
request.setCannedAcl(CannedAccessControlList.PublicRead);
}
cosclient.createBucket(request);
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class BucketDemo method CreateBucketDemo.
// 创建bucket
public static void CreateBucketDemo() {
// 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";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
// 设置bucket的权限为PublicRead(公有读私有写), 其他可选有私有读写, 公有读私有写
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
Bucket bucket = cosclient.createBucket(createBucketRequest);
// 关闭客户端
cosclient.shutdown();
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPrivate.
@Test
public void testCreateDeleteBucketPrivate() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pri-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.Private);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
assertTrue(cosclient.doesBucketExist(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
Aggregations