Demo Project of Image Moderation
This demo project corresponds to the POST /v1.0/moderation/image URI. Replace the AK/SK information with the actual AK/SK to run the demo.
Sample Code
- Configure the AK and SK pair and region information for accessing a service in the ModerationImageContentDemo.java file.
1 2 3 4 5 6 7 8 9
// 1. Configure the basic information for accessing Image Moderation and generate a client connection object. AisAccess service = ServiceAccessBuilder.builder() .ak("######") // your ak .sk("######") // your sk .region("cn-north-4") // Content Moderation in CN North-Beijing4 (cn-north-4) and CN East-Shanghai1 (cn-east-3) .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();
- 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 ModerationImageContentDemo.java file.
1 2 3 4 5 6 7
public static void main(String[] args) throws IOException { ModerationImageContentDemo tool = new ModerationImageContentDemo(); tool.imageContentCheck("https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg"); byte[] imageBytes = FileUtils.readFileToByteArray(new File("data/moderation-demo-1.jpg")); tool.imageContentCheck(imageBytes); }
- Execute the ModerationImageContentDemo.java file. If 200 is displayed on the console, the program is successfully executed. The is displayed on the console. See Figure 1.
Last Article: Moderation (Image)
Next Article: SDK Projects Using Token Authentication

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.