Image upload using okHttp
<p>i want to upload image using <strong>okhttp</strong> but i am not able to find MultipartBuilder for Post Image.What can i use instead of this.</p>
<p>Here is my code</p>
<pre class="lang-java prettyprint-override"><code>
public static JSONObject uploadImage(File file) {

    try {

        final MediaType MEDIA_TYPE_PNG = MediaType.parse(&quot;image/png&quot;);

        RequestBody req = new MultipartBuilder().setType(MultipartBody.FORM)
            .addFormDataPart(&quot;userid&quot;, &quot;8457851245&quot;)
            .addFormDataPart(
                &quot;userfile&quot;,
                &quot;profile.png&quot;,
                RequestBody.create(MEDIA_TYPE_PNG, file)
            )
            .build();

        Request request = new Request.Builder()
            .url(&quot;url&quot;)
            .post(req)
            .build();

        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();

        Log.d(&quot;response&quot;, &quot;uploadImage:&quot; + response.body().string());

        return new JSONObject(response.body().string());

    } catch (UnknownHostException | UnsupportedEncodingException e) {
        Log.e(TAG, &quot;Error: &quot; + e.getLocalizedMessage());
    } catch (Exception e) {
        Log.e(TAG, &quot;Other Error: &quot; + e.getLocalizedMessage());
    }
    return null;
}
</code></pre>
<p>Thanks in advance.</p>