Help Center> Content Moderation> SDK Reference> Using Java SDK (Deprecated)> Demo Project of Image Clarity Detect

Demo Project of Image Clarity Detect

This demo project corresponds to the POST /v1.0/moderation/image/clarity-detect URI. Replace the AK/SK information with the actual AK/SK to run the demo.

Sample Code

  1. Configure the AK/SK in the ModerationClarityDemo.java file.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    // 1. Configure the basic information for accessing Image Clarity Detect and generate a client connection object.
    AisAccess service = ServiceAccessBuilder.builder()		
            .ak("######")                       // your ak
            .sk("######")                       // your sk
    .region("cn-north-1") // Configuration of Content Moderation in the CN North-Beijing1 (cn-north-1) region
            .connectionTimeout(5000)            // Timeout limit for connecting to the target URL
            .connectionRequestTimeout(1000)     // Timeout limit for obtaining available connections from the connection pool
            .socketTimeout(20000)               // Timeout limit for obtaining server response data
            .build();
    
  2. Select a local image or use the default image of the sample project, and modify the image file path (data/moderation-demo-1.jpg) in the ModerationClarityDemo.java file.
    1
    2
    3
    4
    5
    6
    //
    // 2. Construct the parameters required for accessing Image Clarity Detect.
    //
    String uri = "/v1.0/moderation/image/clarity-detect";
    byte[] fileData = FileUtils.readFileToByteArray(new File("data/moderation-demo-1.jpg"));
    String fileBase64Str = Base64.encodeBase64String(fileData);
    
  3. Execute the ModerationClarityDemo.java file. If 200 is displayed on the console, the program is successfully executed. The recognition result is displayed on the console, as shown in Figure 1.
    Figure 1 Execution result