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

Submitting a Task

  1. This section describes how to use the Image Moderation SDK by AK/SK authentication.

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

    using System;
    using System.Collections.Generic;
    using HuaweiCloud.SDK.Core;
    using HuaweiCloud.SDK.Core.Auth;
    using HuaweiCloud.SDK.Moderation;
    using HuaweiCloud.SDK.Moderation.V2;
    using HuaweiCloud.SDK.Moderation.V2.Model;
    
    namespace RunTaskSumbitSolution
    {
        class Program
        {
            static void Main(string[] args)
            {
           //Enter your AK/SK.
                const string ak = "<YOUR AK>";
                const string sk = "<YOUR SK>";
    
                var config = HttpConfig.GetDefaultConfig();
                config.IgnoreSslVerification = true;
                var auth = new BasicCredentials(ak, sk);
    
                var client = ModerationClient.NewBuilder()
                        .WithCredential(auth)
                        .WithRegion(ModerationRegion.ValueOf("xxx"))  //Replace xxx with the region where the service is located.
                        .WithHttpConfig(config)
                        .Build();
    
                var req = new RunTaskSumbitRequest
                {
                };
                List<TaskSumbitReq.CategoriesEnum> listTaskSumbitReqCategories = new List<TaskSumbitReq.CategoriesEnum>();
                listTaskSumbitReqCategories.Add(TaskSumbitReq.CategoriesEnum.FromValue("porn"));
                List<String> listTaskSumbitReqUrls = new List<String>();
                listTaskSumbitReqUrls.Add("https://XXX.jpg");    //Replace it with an image URL that can be accessed from the Internet.
                req.Body = new TaskSumbitReq()
                {
                    Categories = listTaskSumbitReqCategories,
                    Urls = listTaskSumbitReqUrls
                };
    
                try
                {
                    var resp = client.RunTaskSumbit(req);
                    var respStatusCode = resp.HttpStatusCode;
                    Console.WriteLine(respStatusCode);
                    Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody));
                }
                catch (RequestTimeoutException requestTimeoutException)
                {
                    Console.WriteLine(requestTimeoutException.ErrorMessage);
                }
                catch (ServiceResponseException clientRequestException)
                {
                    Console.WriteLine(clientRequestException.HttpStatusCode);
                    Console.WriteLine(clientRequestException.ErrorCode);
                    Console.WriteLine(clientRequestException.ErrorMsg);
                }
                catch (ConnectionException connectionException)
                {
                    Console.WriteLine(connectionException.ErrorMessage);
                }
            }
        }
    }
  2. If 200 is displayed on the console, the code is successfully executed. The result of submitting the Image Moderation (Asynchronous Batch) task is displayed on the console.
    200
    {'result': {'job_id': 'xxx'}}