tencent cloud

masukan

File Moderation

Terakhir diperbarui:2024-02-02 14:36:36

    Overview

    This document describes how to use the content moderation feature provided by Cloud Infinite (CI). CI fully integrates the processing capabilities with the COS SDK.
    Note:
    To use the content moderation service, you need to have the permission to use CI:
    For root accounts, click here for role authorization.
    This document provides an overview of APIs and SDK code samples for file moderation.
    API
    Description
    Submits file moderation job.
    Queries the result of specified file moderation job.

    Submitting File Moderation Job

    Feature description

    This API is used to submit a file moderation job, which can check your file for sensitive or non-compliant information. The file moderation feature combines the file preview feature of COS to moderate files by converting them into images and leveraging image content moderation and OCR capabilities.
    The following example shows how to submit a file moderation job and then query the result by JobId.
    Note:
    To perform this operation, the bucket should have CI features enabled.
    File moderation APIs are supported starting from v5.4.24. To download the latest SDK, go to Releases or see Getting Started.
    To view the version change log, go to GitHub.

    Sample code

    using COSXML.Model.CI;
    using COSXML.Auth;
    using System;
    using System.Threading;
    using COSXML;
    
    namespace COSSnippet
    {
    public class SubmitDocumentCensorJobModel {
    
    private CosXml cosXml;
    
    SubmitDocumentCensorJobModel() {
    CosXmlConfig config = new CosXmlConfig.Builder()
    .SetRegion("COS_REGION") // Set the default region. For the abbreviations for COS regions, visit https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.
    .Build();
    
    string secretId = "SECRET_ID"; // `SecretId` of your TencentCloud API key. For more information on how to get it, visit https://console.tencentcloud.com/cam/capi.
    string secretKey = "SECRET_KEY"; // `SecretKey` of your TencentCloud API key. For more information on how to get it, visit https://console.tencentcloud.com/cam/capi.
    long durationSecond = 600; // Validity period of the request signature in seconds
    QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
    secretKey, durationSecond);
    
    this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
    }
    
    /// Submit the file moderation job
    public string SubmitDocumentCensorJob()
    {
    // Bucket name, which must be in the format of `bucketname-APPID`. For more information on how to get the `APPID`, visit https://console.tencentcloud.com/developer.
    string bucket = "examplebucket-1250000000"; // Note: To perform this operation, the bucket should have the content moderation feature enabled.
    SubmitDocumentCensorJobRequest request = new SubmitDocumentCensorJobRequest(bucket);
    request.SetUrl("url"); // URL of the file to be moderated, which should be replaced with that of the actual file.
    // The scene to be moderated, such as `Porn` (pornography) and `Ads` (advertising). You can pass in multiple types and separate them by comma, such as `Porn,Ads`.
    request.SetDetectType("Porn,Ads");
    // Execute the request
    SubmitCensorJobResult result = cosXml.SubmitDocumentCensorJob(request);
    Console.WriteLine(result.GetResultInfo());
    Console.WriteLine(result.censorJobsResponse.JobsDetail.JobId);
    Console.WriteLine(result.censorJobsResponse.JobsDetail.State);
    Console.WriteLine(result.censorJobsResponse.JobsDetail.CreationTime);
    return result.censorJobsResponse.JobsDetail.JobId;
    }
    
    static void Main(string[] args)
    {
    SubmitDocumentCensorJobModel m = new SubmitDocumentCensorJobModel();
    /// Submit the moderation job
    string JobId = m.SubmitDocumentCensorJob();
    }
    }
    }
    
    Note:
    For more complete samples, visit GitHub.

    Querying File Moderation Job

    Feature description

    This API is used to query the status and result of a file moderation job.

    Sample code

    using COSXML.Model.CI;
    using COSXML.Auth;
    using System;
    using System.Threading;
    using COSXML;
    
    namespace COSSnippet
    {
    public class SubmitDocumentCensorJobModel {
    
    private CosXml cosXml;
    
    SubmitDocumentCensorJobModel() {
    CosXmlConfig config = new CosXmlConfig.Builder()
    .SetRegion("COS_REGION") // Set the default region. For the abbreviations for COS regions, visit https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.
    .Build();
    
    string secretId = "SECRET_ID"; // `SecretId` of your TencentCloud API key. For more information on how to get it, visit https://console.tencentcloud.com/cam/capi.
    string secretKey = "SECRET_KEY"; // `SecretKey` of your TencentCloud API key. For more information on how to get it, visit https://console.tencentcloud.com/cam/capi.
    long durationSecond = 600; // Validity period of the request signature in seconds
    QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
    secretKey, durationSecond);
    
    this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
    }
    
    /// Query the file moderation job result
    public void GetDocumentCensorJobResult(string JobId)
    {
    // Bucket name, which must be in the format of `bucketname-APPID`. For more information on how to get the `APPID`, visit https://console.tencentcloud.com/developer.
    string bucket = "examplebucket-1250000000"; // Note: To perform this operation, the bucket should have the content moderation feature enabled.
    GetDocumentCensorJobRequest request = new GetDocumentCensorJobRequest(bucket, JobId);
    // Execute the request
    GetDocumentCensorJobResult result = cosXml.GetDocumentCensorJob(request);
    Console.WriteLine(result.GetResultInfo());
    
    // Read the moderation result
    Console.WriteLine(result.resultStruct.JobsDetail.State);
    Console.WriteLine(result.resultStruct.JobsDetail.JobId);
    Console.WriteLine(result.resultStruct.JobsDetail.Suggestion);
    Console.WriteLine(result.resultStruct.JobsDetail.CreationTime);
    Console.WriteLine(result.resultStruct.JobsDetail.Url);
    Console.WriteLine(result.resultStruct.JobsDetail.PageCount);
    Console.WriteLine(result.resultStruct.JobsDetail.Labels);
    Console.WriteLine(result.resultStruct.JobsDetail.Labels.PornInfo.HitFlag);
    Console.WriteLine(result.resultStruct.JobsDetail.Labels.PornInfo.Score);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.Url);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.Text);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.PageNumber);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.PornInfo.HitFlag);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.PornInfo.SubLabel);
    Console.WriteLine(result.resultStruct.JobsDetail.PageSegment.Results.PornInfo.Score);
    }
    
    static void Main(string[] args)
    {
    SubmitDocumentCensorJobModel m = new SubmitDocumentCensorJobModel();
    /// Enter the `JobId` that is returned during moderation job submission and uniquely identifies this moderation job
    string JobId = "xxx";
    /// Query the moderation job result
    m.GetDocumentCensorJobResult(JobId);
    }
    }
    }
    
    Note:
    For more complete samples, visit GitHub.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24