Search in sources :

Example 81 with Region

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

the class BucketDemo method JudgeBucketExistDemo.

// 查询bucket是否存在
public static void JudgeBucketExistDemo() {
    // 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);
    String bucketName = "publicreadbucket-1251668577";
    // 判断bucket是否存在
    cosclient.doesBucketExist(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 82 with Region

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

the class BucketDemo method ListBuckets.

public static void ListBuckets() {
    // 1 初始化用户身份信息(appid, secretId, secretKey)
    COSCredentials cred = new BasicCOSCredentials("AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "****************************");
    // 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);
    List<Bucket> buckets = cosclient.listBuckets();
    for (Bucket bucket : buckets) {
        System.out.println(bucket.getName());
        System.out.println(bucket.getLocation());
        System.out.println(bucket.getOwner());
        System.out.println(bucket.getType());
        System.out.println(bucket.getBucketType());
    }
}
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) Bucket(com.qcloud.cos.model.Bucket) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 83 with Region

use of com.qcloud.cos.region.Region 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();
}
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) Bucket(com.qcloud.cos.model.Bucket) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 84 with Region

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

the class BucketDomainDemo method SetGetDeleteBucketDomainDemo.

public static void SetGetDeleteBucketDomainDemo() {
    // 1 初始化用户身份信息(secretId, secretKey)
    COSCredentials cred = new BasicCOSCredentials("AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
    // 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";
    BucketDomainConfiguration bucketDomainConfiguration = new BucketDomainConfiguration();
    DomainRule domainRule = new DomainRule();
    domainRule.setStatus(DomainRule.ENABLED);
    domainRule.setType(DomainRule.REST);
    domainRule.setName("test.com");
    // domainRule.setForcedReplacement(DomainRule.TXT);
    bucketDomainConfiguration.getDomainRules().add(domainRule);
    cosclient.setBucketDomainConfiguration(bucketName, bucketDomainConfiguration);
    BucketDomainConfiguration bucketDomainConfiguration1 = cosclient.getBucketDomainConfiguration(bucketName);
    System.out.println(bucketDomainConfiguration1.getDomainTxtVerification());
    for (DomainRule rule : bucketDomainConfiguration1.getDomainRules()) {
        System.out.println(rule.getName());
        System.out.println(rule.getStatus());
        System.out.println(rule.getType());
        System.out.println(rule.getClass());
    }
    cosclient.deleteBucketDomainConfiguration(bucketName);
    BucketDomainConfiguration bucketDomainConfiguration2 = cosclient.getBucketDomainConfiguration(bucketName);
    assert (bucketDomainConfiguration2 == null);
}
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) BucketDomainConfiguration(com.qcloud.cos.model.BucketDomainConfiguration) DomainRule(com.qcloud.cos.model.DomainRule)

Example 85 with Region

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

the class BucketIntelligentTierDemo method main.

public static void main(String[] args) {
    // 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 = "mybucket-1251668577";
    BucketIntelligentTierConfiguration bucketIntelligentTierConfiguration = new BucketIntelligentTierConfiguration();
    bucketIntelligentTierConfiguration.setStatus(BucketIntelligentTierConfiguration.ENABLED);
    bucketIntelligentTierConfiguration.setTransition(new BucketIntelligentTierConfiguration.Transition(30));
    SetBucketIntelligentTierConfigurationRequest setBucketIntelligentTierConfigurationRequest = new SetBucketIntelligentTierConfigurationRequest();
    setBucketIntelligentTierConfigurationRequest.setBucketName(bucketName);
    setBucketIntelligentTierConfigurationRequest.setIntelligentTierConfiguration(bucketIntelligentTierConfiguration);
    cosclient.setBucketIntelligentTieringConfiguration(setBucketIntelligentTierConfigurationRequest);
    BucketIntelligentTierConfiguration bucketIntelligentTierConfiguration1 = cosclient.getBucketIntelligentTierConfiguration(bucketName);
    System.out.println(bucketIntelligentTierConfiguration1.getStatus());
    System.out.println(bucketIntelligentTierConfiguration1.getTransition().getDays());
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BucketIntelligentTierConfiguration(com.qcloud.cos.model.BucketIntelligentTierConfiguration) SetBucketIntelligentTierConfigurationRequest(com.qcloud.cos.model.SetBucketIntelligentTierConfigurationRequest) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Aggregations

Region (com.qcloud.cos.region.Region)121 COSCredentials (com.qcloud.cos.auth.COSCredentials)105 ClientConfig (com.qcloud.cos.ClientConfig)103 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)101 COSClient (com.qcloud.cos.COSClient)99 CosClientException (com.qcloud.cos.exception.CosClientException)40 CosServiceException (com.qcloud.cos.exception.CosServiceException)38 File (java.io.File)23 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 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)11 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)8 Copy (com.qcloud.cos.transfer.Copy)8 Test (org.junit.Test)8 CopyResult (com.qcloud.cos.model.CopyResult)7 LinkedList (java.util.LinkedList)7 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)6