title: Upload binary file with retrofit android?
body: <p>I have image file to be uploaded to server. The API is to be of <code>Content-Type:application/x-www-form-urlencoded</code>.</p>
  
  <p>Below is my interface method</p>
  
  <pre><code>@Headers("Content-Type: application/octet-stream")
  @PUT
  Call&lt;UserIdentity&gt; putUserProfileImage(@Url String url,
                                         @Body RequestBody file);
  </code></pre>
  
  <p>This is my method call</p>
  
  <pre><code> RequestBody requestBody = RequestBody
              .create(MediaType.parse("application/octet-stream"), profileImage);
  
  
      appCMSUserIdentityRest.putUserProfileImage(url, requestBody).enqueue(new Callback&lt;UserIdentity&gt;() {
          @Override
          public void onResponse(@NonNull Call&lt;UserIdentity&gt; call,
                                 @NonNull Response&lt;UserIdentity&gt; response) {
              if (response.body() != null) {
                  Observable.just(response.body())
                          .onErrorResumeNext(throwable -&gt; Observable.empty())
                          .subscribe(userIdentityAction);
              }else{
                  Observable.just((UserIdentity) null)
                          .onErrorResumeNext(throwable -&gt; Observable.empty())
                          .subscribe(userIdentityAction);
              }
          }
  
          @Override
          public void onFailure(@NonNull Call&lt;UserIdentity&gt; call, @NonNull Throwable t) {
              Observable.just((UserIdentity) null)
                      .onErrorResumeNext(throwable -&gt; Observable.empty())
                      .subscribe(userIdentityAction);
          }
      });
  }
  </code></pre>
  
  <p>I keep getting bad request error.</p>