use of com.qcloud.cos.ClientConfig in project yili-music by programmer-yili.
the class CosStorageServiceImpl method createCOSClient.
// Todo: 改造client获取方法
COSClient createCOSClient() {
// 这里需要已经获取到临时密钥的结果。
// 临时密钥的生成参考 https://cloud.tencent.com/document/product/436/14048#cos-sts-sdk
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// ClientConfig 中包含了后续请求 COS 的客户端设置:
ClientConfig clientConfig = new ClientConfig();
// 设置 bucket 的地域
// COS_REGION 请参照 https://cloud.tencent.com/document/product/436/6224
clientConfig.setRegion(new Region(region));
// 设置请求协议, http 或者 https
// 5.6.53 及更低的版本,建议设置使用 https 协议
// 5.6.54 及更高版本,默认使用了 https
clientConfig.setHttpProtocol(HttpProtocol.https);
// 以下的设置,是可选的:
// 设置 socket 读取超时,默认 30s
clientConfig.setSocketTimeout(30 * 1000);
// 设置建立连接超时,默认 30s
clientConfig.setConnectionTimeout(30 * 1000);
return new COSClient(cred, clientConfig);
}
use of com.qcloud.cos.ClientConfig in project e3mall by colg-cloud.
the class TencentCosTest method testName.
@Test
public void testName() {
COSCredentials cred = new BasicCOSCredentials("AKIDUvjV6VEvvjS4Vliw360iEYpvpgMrqMKF", "sY3NVSL8kLk8KK8lIftzud9VggU5Vkne");
// 采用了新的region名字,可用region的列表可以在官网文档中获取,也可以参考下面的XML SDK和JSON SDK的地域对照表
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket的名字需要的包含appId
String bucketName = "colg-1256242877";
// 上传文件
File localFile = new File(PROJECT_PATH + "\\src\\test\\resources\\images\\FastDfs架构.png");
String key = "colg.png";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
// 设置存储类型, 默认是标准(Standard), 低频(standard_ia)
putObjectRequest.setStorageClass(StorageClass.Standard);
PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
// putObjectResult会返回文件的etag
String etag = putObjectResult.getETag();
log.info("etag: {}", etag);
// 关闭客户端
cosclient.shutdown();
}
use of com.qcloud.cos.ClientConfig in project xian by happyyangyuan.
the class AbsFileOperate method getCosClient.
public COSClient getCosClient() {
if (cosClient == null) {
cosClient = new COSClient(10053621, "AKID5iJcsYewRYIJhqQsoaLQ7Ks1XIO6eYPs", "Gm0nqHOPzUG1MRRJnBLX4UwwQMoh8v4y");
ClientConfig config = new ClientConfig();
config.setRegion("sh");
cosClient.setConfig(config);
}
return cosClient;
}
use of com.qcloud.cos.ClientConfig in project platform by elveahuang.
the class CosStorageServiceImpl method getClient.
/**
* @see StorageService#getClient()
*/
@Override
public COSClient getClient() {
COSCredentials credentials = new BasicCOSCredentials(this.config.getAccessKey(), this.config.getSecretKey());
Region region = new Region(this.config.getEndpoint());
ClientConfig clientConfig = new ClientConfig(region);
return new COSClient(credentials, clientConfig);
}
use of com.qcloud.cos.ClientConfig in project litemall by linlinjava.
the class TencentStorage method getCOSClient.
private COSClient getCOSClient() {
if (cosClient == null) {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// 2 设置bucket的区域, COS地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region(region));
cosClient = new COSClient(cred, clientConfig);
}
return cosClient;
}
Aggregations