All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.guang19.cosservice.template.buckettemplate.DefaultTenCloudCOSBucketTemplate Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.github.guang19.cosservice.template.buckettemplate;

import com.github.guang19.cosservice.config.TenCloudCOSClientProperties;
import com.github.guang19.cosservice.util.COSUtil;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.model.Bucket;
import com.qcloud.cos.model.CannedAccessControlList;
import com.qcloud.cos.model.CreateBucketRequest;

/**
 * @author yangguang
 * @date 2020/2/3
 * @description 

默认采用此模板进行腾讯云COS存储桶服务

*/ public class DefaultTenCloudCOSBucketTemplate extends BaseTenCloudCOSBucketTemplate { /** *

构造基础模板

* @param cosProperties cos客户端属性 */ public DefaultTenCloudCOSBucketTemplate(TenCloudCOSClientProperties cosProperties) { super(cosProperties); } /** *

创建存储桶

* * @param bucketName 存储桶名 * @return 创建好的存储桶bucket */ @Override public Bucket createBucket(String bucketName) { return createBucket(bucketName,CannedAccessControlList.Private); } /** *

创建公有读写的存储桶

* * @param bucketName 存储桶名 * @return 公有读写的存储桶 */ @Override public Bucket createBucketPublicReadAndWrite(String bucketName) { return createBucket(bucketName,CannedAccessControlList.PublicReadWrite); } /** *

创建公有读私有写的存储桶

* * @param bucketName 存储桶名 * @return 公有读私有写的存储桶 */ @Override public Bucket createBucketPublicRead(String bucketName) { return createBucket(bucketName,CannedAccessControlList.PublicRead); } /** *

创建存储桶模板

* @param bucketName 存储桶名 * @param accessControlList 访问权限 * @return 创建好的存储桶 */ private Bucket createBucket(String bucketName, CannedAccessControlList accessControlList) { COSUtil.assertObjectNull(bucketName); CreateBucketRequest createBucketRequest = new CreateBucketRequest(getStandardBucketName(bucketName)); createBucketRequest.setCannedAcl(accessControlList); Bucket bucket = null; try { bucket = cosClient.createBucket(createBucketRequest); } catch (CosClientException e) { logger.error("error during create bucket : " .concat(e.getMessage())); } finally { close(); } return bucket; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy