Updated on 2025-07-02 GMT+08:00

Creating a Video Moderation Job

  1. This section describes how to create a video moderation job using the video moderation SDK and AK/SK.

    In the sample code, you can use withUrls of the RunCreateVideoModerationJobRequest class to configure the URL of the video to be reviewed (only the URL mode is supported). After the configuration is complete, run the code.

    const core = require('@huaweicloud/huaweicloud-sdk-core');
    const moderation = require("@huaweicloud/huaweicloud-sdk-moderation");
    // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.
    // In this example, the AK and SK are stored in environment variables for identity authentication. Before running this example, configure environment variables HUAWEICLOUD_SDK_AK, HUAWEICLOUD_SDK_SK, and HUAWEICLOUD_SDK_PROJECT_ID.
    const ak = process.env.HUAWEICLOUD_SDK_AK;
    const sk = process.env.HUAWEICLOUD_SDK_SK;
    const projectId = process.env.HUAWEICLOUD_SDK_PROJECT_ID;
    
    const endpoint = "https://moderation.ap-southeast-3.myhuaweicloud.com"; //Replace ap-southeast-3 with the region where the service is located.
    const credentials = new core.BasicCredentials()
                         .withAk(ak)
                         .withSk(sk) 
                         .withProjectId(project_id)
    const client = moderation.v3.ModerationClient.newBuilder()
                                .withCredential(credentials)
                                .withEndpoint(endpoint)
                                .build();
    const request = new moderation.v3.RunCreateVideoModerationJobRequest();
    const body = new moderation.v3.VideoCreateRequest();
    const listbodyAudioCategories = new Array();
    listbodyAudioCategories.push("porn");
    const listbodyImageCategories = new Array();
    listbodyImageCategories.push("porn");
    const databody = new moderation.v3.VideoCreateRequestData();
    databody.withUrl("http://xxx.xx.xxxx")
     .withFrameInterval(5);
    body.withAudioCategories(listbodyAudioCategories);
    body.withImageCategories(listbodyImageCategories);
    body.withEventType("default");
    body.withData(databody);
    request.withBody(body);
    const result = client.runCreateVideoModerationJob(request);
    result.then(result => {
        console.log("JSON.stringify(result)::" + JSON.stringify(result));
    }).catch(ex => {
        console.log("exception:" + JSON.stringify(ex));
    });
  2. The console returns the submission result of the creation request and the video moderation job creation result.
    JSON.stringify(result)::{"request_id": "dbbcb75d1a174bfa899a38be38fdd107", "job_id": "xxx"}