Search in sources :

Example 1 with ImageAuditingRequest

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

the class ImageAuditingDemo method imageAuditing.

/**
 * createImageAuditingJob 接口用于创建图片审核任务。(发送单个任务 推荐)
 *
 * @param client
 */
public static void imageAuditing(COSClient client) {
    // 1.创建任务请求对象
    ImageAuditingRequest request = new ImageAuditingRequest();
    // 2.添加请求参数 参数详情请见api接口文档
    // 2.1设置请求bucket
    request.setBucketName("demo-123456789");
    // 2.2设置审核类型
    request.setDetectType("porn");
    // 2.3设置bucket中的图片位置
    request.setObjectKey("1.jpg");
    // 2.4设置图片压缩参数 0(不压缩),1(压缩)默认为零
    request.setLargeImageDetect("1");
    // 3.调用接口,获取任务响应对象
    ImageAuditingResponse response = client.imageAuditing(request);
    // 4调用工具类,获取各审核类型详情集合 (也可自行根据业务解析)
    List<AuditingInfo> imageInfoList = AuditingResultUtil.getImageInfoList(response);
    System.out.println(response);
}
Also used : ImageAuditingResponse(com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse) BatchImageAuditingResponse(com.qcloud.cos.model.ciModel.auditing.BatchImageAuditingResponse) BatchImageAuditingRequest(com.qcloud.cos.model.ciModel.auditing.BatchImageAuditingRequest) ImageAuditingRequest(com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest) AuditingInfo(com.qcloud.cos.model.ciModel.auditing.AuditingInfo)

Example 2 with ImageAuditingRequest

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

the class TransferManager method batchPostImageAuditing.

public MultipleImageAuditingImpl batchPostImageAuditing(List<ImageAuditingRequest> requestList) {
    String description = "Send image auditing jobs in bulk";
    TransferProgress transferProgress = new TransferProgress();
    List<ImageAuditingImpl> imageAuditingList = new ArrayList<>();
    final MultipleImageAuditingImpl multipleImageAuditing = new MultipleImageAuditingImpl(description, transferProgress, imageAuditingList);
    multipleImageAuditing.setMonitor(new MultipleFileTransferMonitor(multipleImageAuditing, imageAuditingList));
    final CountDownLatch latch = new CountDownLatch(1);
    MultipleFileTransferStateChangeListener transferListener = new MultipleFileTransferStateChangeListener(latch, multipleImageAuditing);
    for (ImageAuditingRequest imageAuditingRequest : requestList) {
        imageAuditingList.add(doImageAuditing(imageAuditingRequest, transferListener));
    }
    latch.countDown();
    return multipleImageAuditing;
}
Also used : MultipleFileTransferStateChangeListener(com.qcloud.cos.event.MultipleFileTransferStateChangeListener) ArrayList(java.util.ArrayList) ImageAuditingRequest(com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with ImageAuditingRequest

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

the class ImageAuditingDemo method batchPostImageAuditing.

/**
 * 批量发送图片审核任务 使用sdk并发发送
 */
public static void batchPostImageAuditing(COSClient client) throws InterruptedException {
    List<ImageAuditingRequest> requestList = new ArrayList<>();
    ImageAuditingRequest request = new ImageAuditingRequest();
    request.setBucketName("demo-123456789");
    request.setObjectKey("1.png");
    request.setDetectType("all");
    requestList.add(request);
    request = new ImageAuditingRequest();
    request.setBucketName("demo-123456789");
    request.setObjectKey("1.jpg");
    request.setDetectType("all");
    requestList.add(request);
    // 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
    ExecutorService threadPool = Executors.newFixedThreadPool(4);
    TransferManager transferManager = new TransferManager(client, threadPool);
    MultipleImageAuditingImpl multipleImageAuditing = transferManager.batchPostImageAuditing(requestList);
    multipleImageAuditing.waitForCompletion();
    List<ImageAuditingImpl> imageAuditingList = multipleImageAuditing.getImageAuditingList();
    for (ImageAuditingImpl imageAuditing : imageAuditingList) {
        System.out.println(imageAuditing.getState());
        System.out.println(imageAuditing.getResponse());
        System.out.println(imageAuditing.getErrMsg());
    }
    transferManager.shutdownNow();
    client.shutdown();
}
Also used : TransferManager(com.qcloud.cos.transfer.TransferManager) MultipleImageAuditingImpl(com.qcloud.cos.transfer.MultipleImageAuditingImpl) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) BatchImageAuditingRequest(com.qcloud.cos.model.ciModel.auditing.BatchImageAuditingRequest) ImageAuditingRequest(com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest) ImageAuditingImpl(com.qcloud.cos.transfer.ImageAuditingImpl) MultipleImageAuditingImpl(com.qcloud.cos.transfer.MultipleImageAuditingImpl)

Aggregations

ImageAuditingRequest (com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest)3 BatchImageAuditingRequest (com.qcloud.cos.model.ciModel.auditing.BatchImageAuditingRequest)2 ArrayList (java.util.ArrayList)2 MultipleFileTransferStateChangeListener (com.qcloud.cos.event.MultipleFileTransferStateChangeListener)1 AuditingInfo (com.qcloud.cos.model.ciModel.auditing.AuditingInfo)1 BatchImageAuditingResponse (com.qcloud.cos.model.ciModel.auditing.BatchImageAuditingResponse)1 ImageAuditingResponse (com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse)1 ImageAuditingImpl (com.qcloud.cos.transfer.ImageAuditingImpl)1 MultipleImageAuditingImpl (com.qcloud.cos.transfer.MultipleImageAuditingImpl)1 TransferManager (com.qcloud.cos.transfer.TransferManager)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1