public static JSONObject uploadImage(File file) { try { final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png"); RequestBody req = new MultipartBuilder().SetType(MultipartBody.FORM).addFormDataPart("userid", "8457851245") .addFormDataPart("userfile", "profile.png", RequestBody.create(MEDIA_TYPE_PNG, file)).build(); Request request = new Request.Builder() .Url("url") .Post(req) .Build(); OkHttpClient client = new OkHttpClient(); Response response = client.newCall(request).execute(); Log.d("response", "uploadImage:" + response.body().string()); return(new JSONObject(response.body().string())); } catch (UnknownHostException | UnsupportedEncodingException e) { Log.e(TAG, "Error: " + e.getLocalizedMessage()); } catch (Exception e)