Search in sources :

Example 1 with DocJobResponse

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

the class DocJobDemo method processDocJob.

/**
 * 文档预览完整调用demo
 */
public static void processDocJob(COSClient client) throws InterruptedException {
    String bucketName = "demo-123456789";
    // 1.获取队列id,需要先开启文档预览功能。
    DocQueueRequest queueRequest = new DocQueueRequest();
    queueRequest.setBucketName(bucketName);
    DocListQueueResponse response = client.describeDocProcessQueues(queueRequest);
    List<MediaQueueObject> queueList = response.getQueueList();
    String queueId = "";
    if (queueList.size() != 0) {
        MediaQueueObject mediaQueueObject = queueList.get(0);
        queueId = mediaQueueObject.getQueueId();
    } else {
        System.out.println("获取队列失败");
        return;
    }
    // 2.发送文档预览任务
    // 2.1添加请求参数 参数详情请见api接口文档
    DocJobRequest request = new DocJobRequest();
    request.setBucketName(bucketName);
    DocJobObject docJobObject = request.getDocJobObject();
    docJobObject.setTag("DocProcess");
    docJobObject.getInput().setObject("1.pdf");
    docJobObject.setQueueId(queueId);
    DocProcessObject docProcessObject = docJobObject.getOperation().getDocProcessObject();
    docProcessObject.setQuality("100");
    docProcessObject.setZoom("100");
    docProcessObject.setEndPage("-1");
    docProcessObject.setTgtType("jpg");
    MediaOutputObject output = docJobObject.getOperation().getOutput();
    output.setRegion(client.getClientConfig().getRegion().getRegionName());
    output.setBucket(bucketName);
    output.setObject("demo/pic-${Number}.jpg");
    // 2.2发送预览请求
    DocJobResponse docProcessJobs = client.createDocProcessJobs(request);
    // 3.轮询查询任务结果(也可以配置队列的回调url,使用回调接口获取任务结果)
    DocJobRequest docJobRequest = new DocJobRequest();
    docJobRequest.setBucketName(bucketName);
    String jobId = docProcessJobs.getJobsDetail().getJobId();
    docJobRequest.setJobId(jobId);
    while (true) {
        DocJobResponse docJobResponse = client.describeDocProcessJob(docJobRequest);
        String state = docJobResponse.getJobsDetail().getState();
        // 判断任务状态
        if ("Success".equalsIgnoreCase(state) || "Failed".equalsIgnoreCase(state)) {
            // 处理业务逻辑
            System.out.println(docJobResponse);
            break;
        } else {
            Thread.sleep(500);
        }
    }
}
Also used : DocQueueRequest(com.qcloud.cos.model.ciModel.queue.DocQueueRequest) DocJobResponse(com.qcloud.cos.model.ciModel.job.DocJobResponse) DocJobObject(com.qcloud.cos.model.ciModel.job.DocJobObject) DocListQueueResponse(com.qcloud.cos.model.ciModel.queue.DocListQueueResponse) DocProcessObject(com.qcloud.cos.model.ciModel.job.DocProcessObject) MediaOutputObject(com.qcloud.cos.model.ciModel.common.MediaOutputObject) DocJobRequest(com.qcloud.cos.model.ciModel.job.DocJobRequest) MediaQueueObject(com.qcloud.cos.model.ciModel.queue.MediaQueueObject)

Example 2 with DocJobResponse

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

the class DocJobDemo method createDocJobs.

/**
 * createDocJobs 接口用于创建异步文档预览任务。
 * 将文档转为指定类型(jpg、png、pdf)并保存至指定的cos路径下
 * 该接口为发送任务,如果需要获取转换结果 需要调用查询接口。
 *
 * @param client
 */
public static void createDocJobs(COSClient client) {
    // 1.创建任务请求对象
    DocJobRequest request = new DocJobRequest();
    // 2.添加请求参数 参数详情请见api接口文档
    request.setBucketName("examplebucket-1250000000");
    DocJobObject docJobObject = request.getDocJobObject();
    docJobObject.setTag("DocProcess");
    docJobObject.getInput().setObject("demo.docx");
    docJobObject.setQueueId("pc02270c617ae4b6d9b0a52cb1c*****");
    DocProcessObject docProcessObject = docJobObject.getOperation().getDocProcessObject();
    docProcessObject.setQuality("100");
    docProcessObject.setZoom("100");
    docProcessObject.setStartPage("1");
    docProcessObject.setEndPage("3");
    docProcessObject.setTgtType("png");
    docProcessObject.setDocPassword("123");
    MediaOutputObject output = docJobObject.getOperation().getOutput();
    output.setRegion("ap-chongqing");
    output.setBucket("examplebucket-1250000000");
    output.setObject("mark/pic-${Page}.jpg");
    // 3.调用接口,获取任务响应对象
    DocJobResponse docProcessJobs = client.createDocProcessJobs(request);
    System.out.println(docProcessJobs);
}
Also used : DocJobResponse(com.qcloud.cos.model.ciModel.job.DocJobResponse) DocJobObject(com.qcloud.cos.model.ciModel.job.DocJobObject) DocProcessObject(com.qcloud.cos.model.ciModel.job.DocProcessObject) MediaOutputObject(com.qcloud.cos.model.ciModel.common.MediaOutputObject) DocJobRequest(com.qcloud.cos.model.ciModel.job.DocJobRequest)

Example 3 with DocJobResponse

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

the class DocJobDemo method describeMediaJob.

/**
 * describeMediaJob 根据jobId查询任务信息
 *
 * @param client
 */
public static void describeMediaJob(COSClient client) {
    // 1.创建任务请求对象
    DocJobRequest request = new DocJobRequest();
    // 2.添加请求参数 参数详情请见api接口文档
    request.setBucketName("examplebucket-1250000000");
    request.setJobId("d75b6ea083df711eb8d09476dfb8*****");
    // 3.调用接口,获取任务响应对象
    DocJobResponse docJobResponse = client.describeDocProcessJob(request);
    System.out.println(docJobResponse);
}
Also used : DocJobResponse(com.qcloud.cos.model.ciModel.job.DocJobResponse) DocJobRequest(com.qcloud.cos.model.ciModel.job.DocJobRequest)

Example 4 with DocJobResponse

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

the class CICommonDemo method processCINotifyResponse.

/**
 * 本示例用于解析回调数据,可通过获取Unmarshallers来进行xml数据的解析
 * 可以通过查看CosClient的接口获取到需要使用的xml解析器
 */
public static void processCINotifyResponse(String response) throws Exception {
    // 这里以文档预览的任务回调为例
    Unmarshallers.DescribeDocJobUnmarshaller describeDocJobUnmarshaller = new Unmarshallers.DescribeDocJobUnmarshaller();
    InputStream is = new ByteArrayInputStream(response.getBytes());
    DocJobResponse docJobResponse = describeDocJobUnmarshaller.unmarshall(is);
    System.out.println(docJobResponse);
}
Also used : Unmarshallers(com.qcloud.cos.internal.Unmarshallers) DocJobResponse(com.qcloud.cos.model.ciModel.job.DocJobResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

DocJobResponse (com.qcloud.cos.model.ciModel.job.DocJobResponse)4 DocJobRequest (com.qcloud.cos.model.ciModel.job.DocJobRequest)3 MediaOutputObject (com.qcloud.cos.model.ciModel.common.MediaOutputObject)2 DocJobObject (com.qcloud.cos.model.ciModel.job.DocJobObject)2 DocProcessObject (com.qcloud.cos.model.ciModel.job.DocProcessObject)2 Unmarshallers (com.qcloud.cos.internal.Unmarshallers)1 DocListQueueResponse (com.qcloud.cos.model.ciModel.queue.DocListQueueResponse)1 DocQueueRequest (com.qcloud.cos.model.ciModel.queue.DocQueueRequest)1 MediaQueueObject (com.qcloud.cos.model.ciModel.queue.MediaQueueObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1