Search in sources :

Example 51 with COSClient

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

the class TransferManagerDemo method downloadDirectory.

// 批量下载
public static void downloadDirectory() {
    // 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-beijing-1"));
    // 3 生成cos客户端
    COSClient cosclient = new COSClient(cred, clientConfig);
    // bucket名需包含appid
    String bucketName = "mybucket-1251668577";
    ExecutorService threadPool = Executors.newFixedThreadPool(4);
    // 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
    TransferManager transferManager = new TransferManager(cosclient, threadPool);
    // 设置要下载的对象的前缀(相当于cos上的一个目录),如果设置成 "",则下载整个 bucket。
    String cos_path = "/prefix";
    // 要保存下载的文件的文件夹的绝对路径
    String dir_path = "/to/mydir";
    try {
        // 返回一个异步结果download, 可同步的调用waitForUploadResult等待download结束.
        MultipleFileDownload download = transferManager.downloadDirectory(bucketName, cos_path, new File(dir_path));
        // 可以选择查看下载进度
        showTransferProgress(download);
        // 或者阻塞等待完成
        download.waitForCompletion();
        System.out.println("download directory done.");
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    transferManager.shutdownNow();
    cosclient.shutdown();
}
Also used : TransferManager(com.qcloud.cos.transfer.TransferManager) MultipleFileDownload(com.qcloud.cos.transfer.MultipleFileDownload) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) CosClientException(com.qcloud.cos.exception.CosClientException) COSClient(com.qcloud.cos.COSClient) CosServiceException(com.qcloud.cos.exception.CosServiceException) ExecutorService(java.util.concurrent.ExecutorService) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) File(java.io.File)

Example 52 with COSClient

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

the class DocumentAuditingJobDemo method main.

public static void main(String[] args) {
    // 1 初始化用户身份信息(secretId, secretKey)。
    COSClient client = ClientUtils.getTestClient();
    // 2 调用要使用的方法。
    describeAuditingDocumentJob(client);
}
Also used : COSClient(com.qcloud.cos.COSClient)

Example 53 with COSClient

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

the class ImageAuditingDemo method main.

public static void main(String[] args) throws InterruptedException {
    // 1 初始化用户身份信息(secretId, secretKey)。
    COSClient client = ClientUtils.getTestClient();
    // 2 调用要使用的方法。
    imageAuditing(client);
}
Also used : COSClient(com.qcloud.cos.COSClient)

Example 54 with COSClient

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

the class ImageLabelDemo method main.

public static void main(String[] args) throws JsonProcessingException {
    // 1 初始化用户身份信息(secretId, secretKey)。
    COSClient client = ClientUtils.getTestClient();
    // 2 调用要使用的方法。
    getImageLabel(client);
}
Also used : COSClient(com.qcloud.cos.COSClient)

Example 55 with COSClient

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

the class ImagePersistenceDemo method main.

public static void main(String[] args) throws Exception {
    COSClient cosClient = ClientUtils.getTestClient();
    persistenceImage(cosClient);
    cosClient.shutdown();
}
Also used : COSClient(com.qcloud.cos.COSClient)

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