Search in sources :

Example 46 with ClientConfig

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

the class ClientUtils method getCosClient.

public static COSClient getCosClient(String secretId, String secretKey, String _region) {
    // 1 初始化用户身份信息(secretId, secretKey)。
    COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
    // 2 设置 bucket 的区域, CI 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
    // clientConfig 中包含了设置 region, https(默认 https), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
    Region region = new Region(_region);
    ClientConfig clientConfig = new ClientConfig(region);
    clientConfig.setHttpProtocol(HttpProtocol.http);
    // 3 生成 cos 客户端。
    return 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)

Example 47 with ClientConfig

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

the class GetAsyncFetchTaskDemo method createCosClient.

public static COSClient createCosClient() {
    COSCredentials cred = new BasicCOSCredentials(ak, sk);
    ClientConfig clientConfig = new ClientConfig(new Region(region));
    clientConfig.setHttpProtocol(HttpProtocol.http);
    return 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)

Example 48 with ClientConfig

use of com.qcloud.cos.ClientConfig in project oss-spring-boot-starter by ArtIsLong.

the class TencentOssConfiguration method tencentOssClient.

private StandardOssClient tencentOssClient(TencentOssConfig tencentOssConfig) {
    Region region = region(tencentOssConfig);
    ClientConfig clientConfig = config(region);
    COSCredentials cosCredentials = cosCredentials(tencentOssConfig);
    COSClient cosClient = cosClient(cosCredentials, clientConfig);
    return tencentOssClient(cosClient, tencentOssConfig);
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig)

Example 49 with ClientConfig

use of com.qcloud.cos.ClientConfig in project mall by wangxl-git.

the class QcloudCloudStorageService method init.

private void init() {
    Credentials credentials = new Credentials(config.getQcloudAppId(), config.getQcloudSecretId(), config.getQcloudSecretKey());
    // 初始化客户端配置
    ClientConfig clientConfig = new ClientConfig();
    // 设置bucket所在的区域,华南:gz 华北:tj 华东:sh
    clientConfig.setRegion(config.getQcloudRegion());
    client = new COSClient(clientConfig, credentials);
}
Also used : COSClient(com.qcloud.cos.COSClient) ClientConfig(com.qcloud.cos.ClientConfig) Credentials(com.qcloud.cos.sign.Credentials)

Example 50 with ClientConfig

use of com.qcloud.cos.ClientConfig in project alluxio by Alluxio.

the class COSUnderFileSystem method createInstance.

/**
 * Constructs a new instance of {@link COSUnderFileSystem}.
 *
 * @param uri the {@link AlluxioURI} for this UFS
 * @param conf the configuration for this UFS
 * @return the created {@link COSUnderFileSystem} instance
 */
public static COSUnderFileSystem createInstance(AlluxioURI uri, UnderFileSystemConfiguration conf) throws Exception {
    String bucketName = UnderFileSystemUtils.getBucketName(uri);
    Preconditions.checkArgument(conf.isSet(PropertyKey.COS_ACCESS_KEY), "Property %s is required to connect to COS", PropertyKey.COS_ACCESS_KEY);
    Preconditions.checkArgument(conf.isSet(PropertyKey.COS_SECRET_KEY), "Property %s is required to connect to COS", PropertyKey.COS_SECRET_KEY);
    Preconditions.checkArgument(conf.isSet(PropertyKey.COS_REGION), "Property %s is required to connect to COS", PropertyKey.COS_REGION);
    Preconditions.checkArgument(conf.isSet(PropertyKey.COS_APP_ID), "Property %s is required to connect to COS", PropertyKey.COS_APP_ID);
    String accessKey = conf.getString(PropertyKey.COS_ACCESS_KEY);
    String secretKey = conf.getString(PropertyKey.COS_SECRET_KEY);
    String regionName = conf.getString(PropertyKey.COS_REGION);
    String appId = conf.getString(PropertyKey.COS_APP_ID);
    COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey);
    ClientConfig clientConfig = createCOSClientConfig(regionName, conf);
    COSClient client = new COSClient(cred, clientConfig);
    return new COSUnderFileSystem(uri, client, bucketName, appId, conf);
}
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) 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