Manual image review

Updated at:

This topic describes how to use the Go software development kit (SDK) to manually review images.

Description

If an image detection result does not meet your expectations, you can manually review the image. For more information about the parameters, see Manual image review.

For more information about API endpoints, see Endpoints.

Note
  • This SDK only supports image URLs. Local files or binary data are not supported.

  • Supported URL types:

    • Public HTTP/HTTPS URLs with a maximum length of 2,048 characters.

    • Alibaba Cloud OSS URLs: oss://<bucket-name>.<endpoint>/<object-name>. You must authorize Content Moderation to access the target OSS bucket, and the bucket must be in the same region as the Content Moderation service. For more information, see Authorize Content Moderation to access OSS storage space.

Prerequisites

Before you begin, make sure you have:

  • Installed Go dependencies. See Installation for the required Go version. Using an unsupported version causes subsequent operation calls to fail.

  • A RAM user AccessKey ID and AccessKey secret stored as environment variables:

    • ALIBABA_CLOUD_ACCESS_KEY_ID

    • ALIBABA_CLOUD_ACCESS_KEY_SECRET

Submit an image for manual review

Sample code

package main

import (
   "encoding/json"
   "fmt"
   "github.com/aliyun/alibaba-cloud-sdk-go/services/green"
   "strconv"
)

func main() {
   /**
    * Note: To improve detection performance, reuse the instantiated client and avoid creating repeated connections.
    * Common ways to obtain environment variables:
    *     Obtain the AccessKey ID of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
    *     Obtain the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    */
   client, _err := green.NewClientWithAccessKey(
        "cn-shanghai", 
        "Get AccessKey ID from environment variable", 
        "Get AccessKey secret from environment variable")
   if _err != nil {
      fmt.Println(_err.Error())
      return
   }
   task := map[string]interface{}{"dataId": "Data ID", "url": "Image URL"}
   // The callback and seed parameters are used for webhook notifications and are optional.
   content, _ := json.Marshal(
      map[string]interface{}{
         "tasks":    [...]map[string]interface{}{task},
         "callback": "Webhook address", "seed": "Random string",
      },
   )

   request := green.CreateImageAsyncManualScanRequest()
   request.SetContent(content)
   response, err := client.ImageAsyncManualScan(request)
   if err != nil {
      fmt.Println(err.Error())
      return
   }
   if response.GetHttpStatus() != 200 {
      fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
   }
   fmt.Println(response.GetHttpContentString())
}

Query the result of a manual image review

Sample code

package main

import (
   "encoding/json"
   "fmt"
   "github.com/aliyun/alibaba-cloud-sdk-go/services/green"
   "strconv"
)

func main() {
   /**
    * Note: To improve detection performance, reuse the instantiated client and avoid creating repeated connections.
    * Common ways to obtain environment variables:
    *     Obtain the AccessKey ID of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
    *     Obtain the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    */
   client, _err := green.NewClientWithAccessKey(
        "cn-shanghai", 
        "Get AccessKey ID from environment variable", 
        "Get AccessKey secret from environment variable")
   if _err != nil {
      fmt.Println(_err.Error())
      return
   }

   content, _ := json.Marshal([...]string{"Manual image review task ID"})

   request := green.CreateImageAsyncManualScanResultsRequest()
   request.SetContent(content)
   response, err := client.ImageAsyncManualScanResults(request)
   if err != nil {
      fmt.Println(err.Error())
      return
   }
   if response.GetHttpStatus() != 200 {
      fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
   }
   fmt.Println(response.GetHttpContentString())
}