Updated on 2023-07-17 GMT+08:00

Submitting a Task

  1. This section describes how to use the Image Moderation (Asynchronous Batch) SDK for submitting a task by AK/SK authentication.

    Replace the AK/SK in the sample code with the actual AK/SK. You can set Urls in TaskSumbitReq to configure the URLs of the images to be reviewed, and then execute the code.

    package main
    
    import (
        "fmt"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/region"
    )
    
    func main() {
           //Enter your AK/SK.
        ak := "<YOUR AK>"
        sk := "<YOUR SK>"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := moderation.NewModerationClient(
            moderation.ModerationClientBuilder().
                WithRegion(region.ValueOf("cn-north-4")).
                WithCredential(auth).
                Build())
    
        request := &model.RunTaskSumbitRequest{}
        var listCategoriesbody = []model.TaskSumbitReqCategories{
            model.GetTaskSumbitReqCategoriesEnum().PORN,
        }
        var listUrlsbody = []string{
            "https://XXX.jpg",   //Replace it with an image URL that can be accessed from the Internet.
        }
        request.Body = &model.TaskSumbitReq{
            Categories: &listCategoriesbody,
            Urls: listUrlsbody,
        }
        response, err := client.RunTaskSumbit(request)
        if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }}
  2. If the task submission result is displayed on the console, the code is successfully executed.
    RunTaskSumbitResponse {"result":{"job_id":"xxx"}}
    Process exiting with code: 0