use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class MultipartUploadDemo method abortPartUploadDemo.
// 终止分块上传
public static void abortPartUploadDemo(String uploadId) {
// 1 初始化用户身份信息(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-guangzhou"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa/bbb.txt";
// uploadid(通过initiateMultipartUpload或者ListMultipartUploads获取)
AbortMultipartUploadRequest abortMultipartUploadRequest = new AbortMultipartUploadRequest(bucketName, key, uploadId);
try {
cosclient.abortMultipartUpload(abortMultipartUploadRequest);
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
cosclient.shutdown();
}
use of com.qcloud.cos.auth.COSCredentials in project RuoYi-Vue-Plus by JavaLionLi.
the class QcloudOssStrategy method init.
@Override
public void init(OssProperties ossProperties) {
super.init(ossProperties);
try {
COSCredentials credentials = new BasicCOSCredentials(properties.getAccessKey(), properties.getSecretKey());
// 初始化客户端配置
ClientConfig clientConfig = new ClientConfig();
// 设置bucket所在的区域,华南:gz 华北:tj 华东:sh
clientConfig.setRegion(new Region(properties.getRegion()));
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
clientConfig.setHttpProtocol(HttpProtocol.https);
} else {
clientConfig.setHttpProtocol(HttpProtocol.http);
}
client = new COSClient(credentials, clientConfig);
createBucket();
} catch (Exception e) {
throw new OssException("腾讯云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
}
isInit = true;
}
use of com.qcloud.cos.auth.COSCredentials in project Ant-Live by PinTeh.
the class TencentConfig method getCosClient.
@Bean
public COSClient getCosClient() {
// 1 初始化用户身份信息(secretId, secretKey)。
COSCredentials cred = new BasicCOSCredentials(iii, kkk);
// 2 设置 bucket 的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
// clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
Region region = new Region("ap-chengdu");
ClientConfig clientConfig = new ClientConfig(region);
// 3 生成 cos 客户端。
return new COSClient(cred, clientConfig);
}
use of com.qcloud.cos.auth.COSCredentials in project RuoYi-Flowable-Plus by KonBAI-Q.
the class QcloudOssStrategy method init.
@Override
public void init(OssProperties ossProperties) {
super.init(ossProperties);
try {
COSCredentials credentials = new BasicCOSCredentials(properties.getAccessKey(), properties.getSecretKey());
// 初始化客户端配置
ClientConfig clientConfig = new ClientConfig();
// 设置bucket所在的区域,华南:gz 华北:tj 华东:sh
clientConfig.setRegion(new Region(properties.getRegion()));
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
clientConfig.setHttpProtocol(HttpProtocol.https);
} else {
clientConfig.setHttpProtocol(HttpProtocol.http);
}
client = new COSClient(credentials, clientConfig);
createBucket();
} catch (Exception e) {
throw new OssException("腾讯云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
}
isInit = true;
}
use of com.qcloud.cos.auth.COSCredentials in project simpleFS by shengdingbox.
the class QCloudOssApiClient method init.
@Override
public QCloudOssApiClient init(FileProperties fileProperties) {
final QcloudFileProperties qcloudFileProperties = fileProperties.getTengxun();
String accessKey = qcloudFileProperties.getAccessKey();
String secretKey = qcloudFileProperties.getSecretKey();
String endpoint = qcloudFileProperties.getEndpoint();
String url = qcloudFileProperties.getUrl();
this.bucketName = qcloudFileProperties.getBucketName();
checkDomainUrl(url);
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey) || StringUtils.isNullOrEmpty(bucketName)) {
throw new ServiceException("[" + this.storageType + "]尚未配置腾讯云,文件上传功能暂时不可用!");
}
COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey);
Region region = new Region(endpoint);
ClientConfig clientConfig = new ClientConfig(region);
cosClient = new COSClient(cred, clientConfig);
return this;
}
Aggregations