Search in sources :

Example 76 with COSClient

use of com.qcloud.cos.COSClient 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;
}
Also used : COSClient(com.qcloud.cos.COSClient) ClientConfig(com.qcloud.cos.ClientConfig)

Example 77 with COSClient

use of com.qcloud.cos.COSClient 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);
}
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 78 with COSClient

use of com.qcloud.cos.COSClient 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;
}
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 79 with COSClient

use of com.qcloud.cos.COSClient in project halo by ruibaby.

the class TencentCosFileHandler method delete.

@Override
public void delete(String key) {
    Assert.notNull(key, "File key must not be blank");
    // Get config
    String region = optionService.getByPropertyOfNonNull(TencentCosProperties.COS_REGION).toString();
    String secretId = optionService.getByPropertyOfNonNull(TencentCosProperties.COS_SECRET_ID).toString();
    String secretKey = optionService.getByPropertyOfNonNull(TencentCosProperties.COS_SECRET_KEY).toString();
    String bucketName = optionService.getByPropertyOfNonNull(TencentCosProperties.COS_BUCKET_NAME).toString();
    COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
    Region regionConfig = new Region(region);
    ClientConfig clientConfig = new ClientConfig(regionConfig);
    // Init OSS client
    COSClient cosClient = new COSClient(cred, clientConfig);
    try {
        cosClient.deleteObject(bucketName, key);
    } catch (Exception e) {
        throw new FileOperationException("附件 " + key + " 从腾讯云删除失败", e);
    } finally {
        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) FileOperationException(run.halo.app.exception.FileOperationException) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) FileOperationException(run.halo.app.exception.FileOperationException)

Example 80 with COSClient

use of com.qcloud.cos.COSClient in project yili-music by programmer-yili.

the class CosStorageServiceImpl method getFileUri.

@Override
public String getFileUri(String fileKey) {
    COSClient cosClient = createCOSClient();
    Date expirationDate = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
    Map<String, String> params = new HashMap<String, String>();
    Map<String, String> headers = new HashMap<String, String>();
    HttpMethodName method = HttpMethodName.GET;
    URL url = cosClient.generatePresignedUrl(bucket, fileKey, expirationDate, method, headers, params);
    cosClient.shutdown();
    return url.toString();
}
Also used : COSClient(com.qcloud.cos.COSClient) HttpMethodName(com.qcloud.cos.http.HttpMethodName) HashMap(java.util.HashMap) Date(java.util.Date) URL(java.net.URL)

Aggregations

COSClient (com.qcloud.cos.COSClient)142 ClientConfig (com.qcloud.cos.ClientConfig)103 Region (com.qcloud.cos.region.Region)99 COSCredentials (com.qcloud.cos.auth.COSCredentials)96 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)93 CosClientException (com.qcloud.cos.exception.CosClientException)38 CosServiceException (com.qcloud.cos.exception.CosServiceException)38 File (java.io.File)22 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)15 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 URL (java.net.URL)6 FileOperationException (run.halo.app.exception.FileOperationException)6 Date (java.util.Date)5