Search in sources :

Example 1 with PicOperations

use of com.qcloud.cos.model.ciModel.persistence.PicOperations 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();
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) LinkedList(java.util.LinkedList) CosServiceException(com.qcloud.cos.exception.CosServiceException) File(java.io.File) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 2 with PicOperations

use of com.qcloud.cos.model.ciModel.persistence.PicOperations in project cos-java-sdk-v5 by tencentyun.

the class ImagePersistenceDemo method persistenceImageWithTransferManager.

public static void persistenceImageWithTransferManager(TransferManager transferManager) throws InterruptedException {
    // bucket名需包含appid
    // api 请参考:https://cloud.tencent.com/document/product/436/46782
    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);
    Upload upload = transferManager.upload(putObjectRequest);
    UploadResult uploadResult = upload.waitForUploadResult();
    CIUploadResult ciUploadResult = uploadResult.getCiUploadResult();
    System.out.println(uploadResult.getRequestId());
    System.out.println(ciUploadResult.getOriginalInfo().getEtag());
    for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
        System.out.println(ciObject.getLocation());
        System.out.println(ciObject.getEtag());
    }
}
Also used : PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) Upload(com.qcloud.cos.transfer.Upload) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) CompleteMultipartUploadResult(com.qcloud.cos.model.CompleteMultipartUploadResult) UploadResult(com.qcloud.cos.model.UploadResult) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) InitiateMultipartUploadResult(com.qcloud.cos.model.InitiateMultipartUploadResult) File(java.io.File) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) LinkedList(java.util.LinkedList) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 3 with PicOperations

use of com.qcloud.cos.model.ciModel.persistence.PicOperations 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();
    }
}
Also used : CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) ImageProcessRequest(com.qcloud.cos.model.ciModel.common.ImageProcessRequest) LinkedList(java.util.LinkedList) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 4 with PicOperations

use of com.qcloud.cos.model.ciModel.persistence.PicOperations 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();
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) LinkedList(java.util.LinkedList) CosServiceException(com.qcloud.cos.exception.CosServiceException) File(java.io.File) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 5 with PicOperations

use of com.qcloud.cos.model.ciModel.persistence.PicOperations in project cos-java-sdk-v5 by tencentyun.

the class QRCodeDemo method identifyQrCodeWithMultipart.

public static void identifyQrCodeWithMultipart(COSClient cosClient) throws FileNotFoundException {
    // 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");
    InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, key);
    InitiateMultipartUploadResult initResult = cosClient.initiateMultipartUpload(request);
    String uploadId = initResult.getUploadId();
    // 上传分块
    List<PartETag> partETags = new LinkedList<>();
    UploadPartRequest uploadPartRequest = new UploadPartRequest();
    uploadPartRequest.setBucketName(bucketName);
    uploadPartRequest.setKey(key);
    uploadPartRequest.setUploadId(uploadId);
    // 设置分块的数据来源输入流
    uploadPartRequest.setInputStream(new FileInputStream(localFile));
    // 设置分块的长度
    // 设置数据长度
    uploadPartRequest.setPartSize(localFile.length());
    // 假设要上传的part编号是10
    uploadPartRequest.setPartNumber(1);
    UploadPartResult uploadPartResult = cosClient.uploadPart(uploadPartRequest);
    PartETag partETag = uploadPartResult.getPartETag();
    partETags.add(partETag);
    // 带上图像处理参数执行合并分块
    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);
    CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
    completeMultipartUploadRequest.setPicOperations(picOperations);
    CompleteMultipartUploadResult completeMultipartUploadResult = cosClient.completeMultipartUpload(completeMultipartUploadRequest);
    // 获取图片处理的结果
    CIUploadResult ciUploadResult = completeMultipartUploadResult.getCiUploadResult();
    System.out.println(completeMultipartUploadResult.getRequestId());
    System.out.println(ciUploadResult.getOriginalInfo().getEtag());
    for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
        System.out.println(ciObject.getLocation());
    }
}
Also used : InitiateMultipartUploadResult(com.qcloud.cos.model.InitiateMultipartUploadResult) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) InitiateMultipartUploadRequest(com.qcloud.cos.model.InitiateMultipartUploadRequest) UploadPartRequest(com.qcloud.cos.model.UploadPartRequest) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) CompleteMultipartUploadResult(com.qcloud.cos.model.CompleteMultipartUploadResult) PartETag(com.qcloud.cos.model.PartETag) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) UploadPartResult(com.qcloud.cos.model.UploadPartResult) File(java.io.File) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject) CompleteMultipartUploadRequest(com.qcloud.cos.model.CompleteMultipartUploadRequest)

Aggregations

CIObject (com.qcloud.cos.model.ciModel.persistence.CIObject)13 CIUploadResult (com.qcloud.cos.model.ciModel.persistence.CIUploadResult)13 PicOperations (com.qcloud.cos.model.ciModel.persistence.PicOperations)13 LinkedList (java.util.LinkedList)13 File (java.io.File)10 CosClientException (com.qcloud.cos.exception.CosClientException)7 CosServiceException (com.qcloud.cos.exception.CosServiceException)7 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)7 CompleteMultipartUploadResult (com.qcloud.cos.model.CompleteMultipartUploadResult)6 InitiateMultipartUploadResult (com.qcloud.cos.model.InitiateMultipartUploadResult)6 PutObjectResult (com.qcloud.cos.model.PutObjectResult)4 CompleteMultipartUploadRequest (com.qcloud.cos.model.CompleteMultipartUploadRequest)3 InitiateMultipartUploadRequest (com.qcloud.cos.model.InitiateMultipartUploadRequest)3 PartETag (com.qcloud.cos.model.PartETag)3 UploadPartRequest (com.qcloud.cos.model.UploadPartRequest)3 UploadPartResult (com.qcloud.cos.model.UploadPartResult)3 UploadResult (com.qcloud.cos.model.UploadResult)3 ImageProcessRequest (com.qcloud.cos.model.ciModel.common.ImageProcessRequest)3 Upload (com.qcloud.cos.transfer.Upload)3 FileInputStream (java.io.FileInputStream)3