Android & Retrofit2 - posting image file in multipart request
<p>I'm making an app in which I have to send image from gallery to server.</p>

<p>These should be headers (according to apiary).</p>

<pre><code>Content-Type:image/jpeg
X-Filename:photo.jpg
</code></pre>

<p>But in logs in interceptor, there is only X-Filename, even though I tried multiple  ways and I'm running out of ideas.</p>

<p>Server responds with 200 but the next call (commit image) returns 500 with error at the end of post.</p>

<p>These are the methods:</p>

<pre><code>    @Multipart
    @POST("uploads")
    Observable&lt;String&gt; uploadImage(
        @Header("Content-Type") String contentType,
        @Header("X-Filename") String fileName,
        @Header("Authorization") String token,
        @Part MultipartBody.Part file
    );

    @GET("uploads/{fileId}/commit")
    Observable&lt;String&gt; commitFile(
        @Header("Content-Type") String type,
        @Header("Authorization") String token,
        @Path("fileId") String fileId
    );
</code></pre>

<p>OkHttp client: </p>

<pre><code>  private OkHttpClient createApiClient(Context context) {
      int cacheSize = 10 * 1024 * 1024; // 10 MiB
      Cache cache = new Cache(context.getCacheDir(), cacheSize);

      OkHttpClient.Builder builder = new OkHttpClient.Builder();
      builder.addInterceptor(chain -&gt; {
          Request request = chain.request().newBuilder().build();
          request.newBuilder().addHeader("Content-Type", "application/json");
          Timber.d("Request: [%s] %s", request.method(), request.url());
          Timber.d("Request: %s", request.headers().toString());
          if (request.body() != null) {
              Timber.d("Request: %s", request.body().toString());
          }
          return chain.proceed(request);
      });
      builder.cache(cache);
      return builder.build();
  }
</code></pre>

<p>Resulting logs:</p>

<pre><code>D/NetModule: Request: [POST] https://winged-guild-133523.appspot.com/api/v1/uploads
D/NetModule: Request: X-Filename: asura.png
                      Authorization: HAYVi3clcqjug53IPS6AYMgzCPGnDE3Si
D/NetModule: Request: retrofit2.RequestBuilder$ContentTypeOverridingRequestBody@7c37f46
</code></pre>

<p>Same thing happens with Postman - <a href="https://i.stack.imgur.com/1VcYm.png" rel="nofollow">Postman screenshot</a></p>

<p>Commit fails with this error: (sorry for ugly formatting)</p>

<pre><code>    {
        "errorCode": "ImagesServiceFailureException",
        "errorParam": "",
        "errorMessage":"com.google.appengine.api.images.ImagesServiceFailureException: "
}
</code></pre>

<p>As I said I'm running out of ideas and would greatly appreciate any help with this upload problem.</p>

<p><strong>(edit) PS:</strong> by omitting <em>@Header("Content-Type") String contentType</em> in app and using <em>application/x-www-form-urlencoded</em> in Postman, image upload and commit are both successful, but Image at returned url has no metadata and therefore can't be displayed.</p>