Building a Simple Image Porn Detection Platform with UCloud UAI‑Censor (Java SpringBoot)
This guide walks through setting up a quick image porn detection platform using UCloud's UAI‑Censor service, covering account creation, obtaining API keys, testing the API, and integrating a simple Java SpringBoot client that evaluates images and returns pass, forbid, or manual‑review suggestions.
The article explains how to quickly build an image porn‑filtering platform by leveraging UCloud's UAI‑Censor service, which currently supports image moderation and will later add terrorism and political content detection.
Data preparation: After failing to find suitable public resources, the author decided to create a custom solution for testing the censorship capabilities.
Account preparation: Register a UCloud account, create a UAI‑Censor application, and obtain the application ID. The service offers a free quota of 2,000 image scans per day, sufficient for testing and small‑scale tools.
Steps to set up the account: Use the provided registration link, create an application with a custom name, and note the generated Application ID. Then retrieve the public and private API keys from the UCloud console.
Obtaining keys: Navigate to the API key management page (https://console.ucloud.cn/uapi/apikey) to view and copy the public and private keys, which are required for authenticated API calls.
Manual API test: By submitting an image URL along with the keys and app ID, the API returns a JSON response. The important field is Result.Porn.Suggestion , which can be pass (allow), forbid (block), or check (manual review). The example test returned pass .
Implementation code (Java SpringBoot):
/**
* @param imageUrl
* @return pass‑allow, forbid‑block, check‑manual review
*/
public String check(String imageUrl) {
String ucloudUrl = "http://api.uai.ucloud.cn/v1/image/scan";
String appId = "uaicensor-rjmvogpx";
String uaicensorPublicKey = null; // replace with your public key
String uaicensorPrivateKey = null; // replace with your private key
// Build request
RestTemplate rest = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
String timestamp = System.currentTimeMillis() + "";
SortedMap
packageParams = new TreeMap<>();
packageParams.put("PublicKey", uaicensorPublicKey);
packageParams.put("ResourceId", appId);
packageParams.put("Timestamp", timestamp);
packageParams.put("Url", imageUrl);
String signature = null;
try {
signature = UCloudUtil.createSign(packageParams, uaicensorPrivateKey);
} catch (Exception e) {
return null;
}
MultiValueMap
param = new LinkedMultiValueMap<>();
param.add("Scenes", "porn");
param.add("Method", "url");
param.add("Url", imageUrl);
headers.setContentType(MediaType.parseMediaType("multipart/form-data; charset=UTF-8"));
headers.set("PublicKey", uaicensorPublicKey);
headers.set("Signature", signature);
headers.set("ResourceId", appId);
headers.set("Timestamp", timestamp);
HttpEntity
> httpEntity = new HttpEntity<>(param, headers);
ResponseEntity
responseEntity = rest.exchange(ucloudUrl, HttpMethod.POST, httpEntity, String.class);
String body = responseEntity.getBody();
JSONObject jsonObject = JSON.parseObject(body);
if (jsonObject.getInteger("RetCode") == 0) {
String res = jsonObject.getJSONObject("Result").getJSONObject("Porn").getString("Suggestion");
return res;
}
return null;
}The code demonstrates how to sign the request, send the image URL to the UAI‑Censor endpoint, and parse the JSON response to obtain the moderation suggestion.
With these steps, readers can set up their own image moderation service and start experimenting with AI‑driven content safety.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.