| Information | |
|---|---|
| Description | Code snippet for calling the v1/smartcare/check API endpoint for a single image. |
| Purpose | The function: Uploads a JPG-encoded image as multipart/form-data |
| Language | Kotlin |
Input Parameters
Section titled “Input Parameters”- jpegBytes:
ByteArray
The raw data containing the compressed JPG image.
Output
Section titled “Output”- errorCode:
int
Integer value representing the type of quality error. Set to 0 when quality check passed. - errorType:
string
String value representing the type of quality error. Set to “pass” when quality check passed.
Snippet
Section titled “Snippet”fun uploadJpegToApi(jpegBytes: ByteArray, apiUrl: String) { val client = OkHttpClient()
// Create multipart body val requestBody = MultipartBody.Builder() .setType(MultipartBody.FORM) .addHeader("Authorization", "Token <your_action_token>") .addFormDataPart( "image", // Field name "frame.jpg", // File name RequestBody.create("image/jpeg".toMediaTypeOrNull(), jpegBytes) ) .build()
// Build POST request val request = Request.Builder() .url(apiUrl) .post(requestBody) .build()
// Execute request asynchronously client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { Log.e("API", "Failed to upload image", e) }
override fun onResponse(call: Call, response: Response) { response.use { if (!response.isSuccessful) { Log.e("API", "Unexpected HTTP code: ${response.code}") return }
val responseBody = response.body?.string() Log.d("API", "Response: $responseBody")
// Example response: {"error_code": 0, "error_type": "PASS"} val json = JSONObject(responseBody ?: "{}") val errorCode = json.optInt("errorCode") val errorType = json.optString("errorType")
Log.d("API", "Error Code: $errorCode, Error Type: $errorType") } } })}- The snippet above uses the
OkHttpdependency for handling the HTTP request.

