use of com.qcloud.cos.exception.CosServiceException 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();
}
use of com.qcloud.cos.exception.CosServiceException in project cos-java-sdk-v5 by tencentyun.
the class ImagePersistenceDemo method persistenceImage.
public static void persistenceImage(COSClient cosClient) {
// bucket名需包含appid
// api 请参考 https://cloud.tencent.com/document/product/436/54050
String bucketName = "examplebucket-1250000000";
String key = "test.jpg";
File localFile = new File("E://test.jpg");
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
PicOperations picOperations = new PicOperations();
picOperations.setIsPicInfo(1);
List<PicOperations.Rule> ruleList = new LinkedList<>();
PicOperations.Rule rule1 = new PicOperations.Rule();
rule1.setBucket(bucketName);
rule1.setFileId("test-1.jpg");
rule1.setRule("imageMogr2/rotate/90");
ruleList.add(rule1);
PicOperations.Rule rule2 = new PicOperations.Rule();
rule2.setBucket(bucketName);
rule2.setFileId("test-2.jpg");
rule2.setRule("imageMogr2/rotate/180");
ruleList.add(rule2);
picOperations.setRules(ruleList);
putObjectRequest.setPicOperations(picOperations);
try {
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
CIUploadResult ciUploadResult = putObjectResult.getCiUploadResult();
System.out.println(putObjectResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
System.out.println(ciObject.getEtag());
}
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
}
use of com.qcloud.cos.exception.CosServiceException in project cos-java-sdk-v5 by tencentyun.
the class ImagePersistenceDemo method persistenceImagePost.
public static void persistenceImagePost(COSClient cosClient) {
String bucketName = "examplebucket-1250000000";
String key = "test.jpg";
ImageProcessRequest imageReq = new ImageProcessRequest(bucketName, key);
PicOperations picOperations = new PicOperations();
picOperations.setIsPicInfo(1);
List<PicOperations.Rule> ruleList = new LinkedList<>();
PicOperations.Rule rule1 = new PicOperations.Rule();
rule1.setBucket(bucketName);
rule1.setFileId("test-1.jpg");
rule1.setRule("imageMogr2/rotate/90");
ruleList.add(rule1);
PicOperations.Rule rule2 = new PicOperations.Rule();
rule2.setBucket(bucketName);
rule2.setFileId("test-2.jpg");
rule2.setRule("imageMogr2/rotate/180");
ruleList.add(rule2);
picOperations.setRules(ruleList);
imageReq.setPicOperations(picOperations);
try {
CIUploadResult ciUploadResult = cosClient.processImage(imageReq);
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
System.out.println(ciObject.getEtag());
}
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
}
use of com.qcloud.cos.exception.CosServiceException in project cos-java-sdk-v5 by tencentyun.
the class QRCodeDemo method identifyQrCode.
public static void identifyQrCode(COSClient cosClient) {
// bucket名需包含appid
// api 请参考 https://cloud.tencent.com/document/product/436/54070
String bucketName = "examplebucket-1250000000";
String key = "qrcode.png";
File localFile = new File("E://qrcode.png");
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
PicOperations picOperations = new PicOperations();
picOperations.setIsPicInfo(1);
List<PicOperations.Rule> ruleList = new LinkedList<>();
PicOperations.Rule rule1 = new PicOperations.Rule();
rule1.setBucket(bucketName);
rule1.setFileId("qrcode-1.png");
rule1.setRule("QRcode/cover/1");
ruleList.add(rule1);
picOperations.setRules(ruleList);
putObjectRequest.setPicOperations(picOperations);
try {
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
CIUploadResult ciUploadResult = putObjectResult.getCiUploadResult();
System.out.println(putObjectResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
}
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
}
use of com.qcloud.cos.exception.CosServiceException in project cos-java-sdk-v5 by tencentyun.
the class BlindWatermarkDemo method addBlindWatermarkToExistImage.
public static void addBlindWatermarkToExistImage(COSClient cosClient) {
// bucket名需包含appid
// api 请参考:https://cloud.tencent.com/document/product/436/46782
String bucketName = "examplebucket-1250000000";
String key = "image/dog.jpg";
ImageProcessRequest imageProcessRequest = new ImageProcessRequest(bucketName, key);
PicOperations picOperations = new PicOperations();
picOperations.setIsPicInfo(1);
List<PicOperations.Rule> ruleList = new LinkedList<>();
PicOperations.Rule rule = new PicOperations.Rule();
rule.setBucket(bucketName);
rule.setFileId("/image/result/dog.jpg");
// 使用盲水印功能,水印图的宽高不得超过原图的1/8
rule.setRule("watermark/3/type/2/image/aHR0cDovL2V4YW1wbGVidWNrZXQtMTI1MDAwMDAwMC5jb3MuYXAtZ3Vhbmd6aG91Lm15cWNsb3VkLmNvbS9zaHVpeWluLnBuZw==");
ruleList.add(rule);
picOperations.setRules(ruleList);
imageProcessRequest.setPicOperations(picOperations);
try {
CIUploadResult ciUploadResult = cosClient.processImage(imageProcessRequest);
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
}
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
}
}
Aggregations