What is the best way to send @Multipart file/bitmap and extra parameters with retrofit 2?
<p>I have a helper class:</p>

<pre><code>public class RequestPart {
    public static RequestBody createFromBitmap(Bitmap bitmap) {
        return RequestBody.create(MediaType.parse("image/png"), Utils.getBytes(bitmap));
    }

    public static RequestBody createFromObject(Object value) {
        return RequestBody.create(
                MediaType.parse("multipart/form-data"), String.valueOf(value));
    }

    public static Map&lt;String, RequestBody&gt; convertMap(Map&lt;String, Object&gt; map) {
        Map&lt;String, RequestBody&gt; result = new HashMap&lt;&gt;();
        for (Map.Entry&lt;String, Object&gt; entry : map.entrySet()) {
            if (entry.getValue() instanceof Bitmap) {
                result.put(entry.getKey(), createFromBitmap((Bitmap) entry.getValue()));
            } else {
                result.put(entry.getKey(), createFromObject(entry.getValue()));
            }
        }
        return result;
    }
}
</code></pre>

<p>I use it this way:</p>

<pre><code>Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();
params.put("profile[param1]", String);
params.put("profile[param1]", Object);
params.put("profile[param1]", int);
params.put("profile[param2]", Bitmap);
params.put("profile[param2]", Bitmap);

retrofitService.updateProfile(RequestPart.convertMap(params));
</code></pre>

<p>Retrofit:</p>

<pre><code>@Multipart
@POST("api-patient/upload/something.json")
Call&lt;User&gt; uploadStateId(@PartMap Map&lt;String, RequestBody&gt; params);
</code></pre>

<p>I tried wrap only Bitmap parameters but when I send a String to server like <code>@PartMap Map&lt;String, String&gt; params</code> it wraps value in double quotes <code>""Value""</code> that's why I use RequestBody for all parametes.</p>

<p>Does any one know the better or simpler way to do this?</p>