Search in sources :

Example 91 with COSCredentials

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();
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosServiceException(com.qcloud.cos.exception.CosServiceException) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosClientException(com.qcloud.cos.exception.CosClientException) Region(com.qcloud.cos.region.Region) AbortMultipartUploadRequest(com.qcloud.cos.model.AbortMultipartUploadRequest) ClientConfig(com.qcloud.cos.ClientConfig)

Example 92 with COSCredentials

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;
}
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) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 93 with COSCredentials

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);
}
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) Bean(org.springframework.context.annotation.Bean)

Example 94 with COSCredentials

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;
}
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) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 95 with COSCredentials

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;
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) ServiceException(com.zhouzifei.tool.common.ServiceException) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) QcloudFileProperties(com.zhouzifei.tool.config.QcloudFileProperties) ClientConfig(com.qcloud.cos.ClientConfig)

Aggregations

COSCredentials (com.qcloud.cos.auth.COSCredentials)112 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)105 Region (com.qcloud.cos.region.Region)105 ClientConfig (com.qcloud.cos.ClientConfig)99 COSClient (com.qcloud.cos.COSClient)96 CosClientException (com.qcloud.cos.exception.CosClientException)42 CosServiceException (com.qcloud.cos.exception.CosServiceException)38 File (java.io.File)22 TransferManager (com.qcloud.cos.transfer.TransferManager)13 ExecutorService (java.util.concurrent.ExecutorService)13 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)12 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)12 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)11 PutObjectResult (com.qcloud.cos.model.PutObjectResult)11 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)10 Copy (com.qcloud.cos.transfer.Copy)8 CopyResult (com.qcloud.cos.model.CopyResult)7 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)7 Date (java.util.Date)7 LinkedList (java.util.LinkedList)7