Search in sources :

Example 21 with ClientConfig

use of com.qcloud.cos.ClientConfig in project cos-java-sdk-v5 by tencentyun.

the class BucketDemo method SetBucketLogging.

// 开启日志存储
public static void SetBucketLogging() {
    // 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 = "examplebucket-1251668577";
    BucketLoggingConfiguration bucketLoggingConfiguration = new BucketLoggingConfiguration();
    // 设置日志存储的 bucket
    bucketLoggingConfiguration.setDestinationBucketName(bucketName);
    // 设置日志存储的前缀
    bucketLoggingConfiguration.setLogFilePrefix("logs/");
    SetBucketLoggingConfigurationRequest setBucketLoggingConfigurationRequest = new SetBucketLoggingConfigurationRequest(bucketName, bucketLoggingConfiguration);
    cosclient.setBucketLoggingConfiguration(setBucketLoggingConfigurationRequest);
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BucketLoggingConfiguration(com.qcloud.cos.model.BucketLoggingConfiguration) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) SetBucketLoggingConfigurationRequest(com.qcloud.cos.model.SetBucketLoggingConfigurationRequest) ClientConfig(com.qcloud.cos.ClientConfig)

Example 22 with ClientConfig

use of com.qcloud.cos.ClientConfig in project cos-java-sdk-v5 by tencentyun.

the class BucketDemo method SetBucketVersioning.

// 开启 bucket 版本控制
public static void SetBucketVersioning() {
    // 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 = "examplebucket-1251668577";
    // 开启版本控制
    BucketVersioningConfiguration bucketVersioningConfiguration = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
    // 关闭版本控制
    // BucketVersioningConfiguration bucketVersioningConfiguration = new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED);
    SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest = new SetBucketVersioningConfigurationRequest(bucketName, bucketVersioningConfiguration);
    cosclient.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest);
    cosclient.shutdown();
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) Region(com.qcloud.cos.region.Region) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) ClientConfig(com.qcloud.cos.ClientConfig)

Example 23 with ClientConfig

use of com.qcloud.cos.ClientConfig 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();
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 24 with ClientConfig

use of com.qcloud.cos.ClientConfig 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());
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BucketPolicy(com.qcloud.cos.model.BucketPolicy) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 25 with ClientConfig

use of com.qcloud.cos.ClientConfig 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);
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Aggregations

ClientConfig (com.qcloud.cos.ClientConfig)107 COSClient (com.qcloud.cos.COSClient)103 Region (com.qcloud.cos.region.Region)103 COSCredentials (com.qcloud.cos.auth.COSCredentials)99 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)96 CosClientException (com.qcloud.cos.exception.CosClientException)40 CosServiceException (com.qcloud.cos.exception.CosServiceException)38 File (java.io.File)22 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)14 PutObjectResult (com.qcloud.cos.model.PutObjectResult)14 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)13 TransferManager (com.qcloud.cos.transfer.TransferManager)13 ExecutorService (java.util.concurrent.ExecutorService)13 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)7 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)7 LinkedList (java.util.LinkedList)7 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)6 FileOperationException (run.halo.app.exception.FileOperationException)6 IOException (java.io.IOException)5 CopyResult (com.qcloud.cos.model.CopyResult)4