Android Integration
Minimal OkHttp client. callTimeout is 300s — upscale is a slow synchronous call.
1. JSON (image URL)
val body = JSONObject().put("image_url", imageUrl).toString()
.toRequestBody("application/json".toMediaType())
val req = Request.Builder().url("$base/upscale").post(body).build()
2. Multipart (file upload)
val multipart = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "upload", bytes.toRequestBody(type.toMediaType()))
.build()
val req = Request.Builder().url("$base/upscale").post(multipart).build()
3. Parse response
http.newCall(req).execute().use { resp ->
val json = JSONObject(resp.body!!.string())
if (json.optString("status") != "success")
throw IllegalStateException(json.optString("message"))
val resultUrl = json.getJSONObject("data").getString("result_url")
}
Notes
- 4K result will OOM on a full decode — downsample to ~1080px with
inSampleSize. - Use a 300s
callTimeout+readTimeout. - applicationId:
com.roosterx.imgupscale4k.
Full demo client: android/ in the repo.
Result
—