title: Retrofit2: Upload an Image with some Form Data-Android
body: <p><a href="https://i.stack.imgur.com/PjFXP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PjFXP.png" alt="The PostMan screenshot"></a></p>
  
  <p>The above screenshot contain the Post method and Response from the server..
  here i am trying to upload an image with some data to my server(catch the image from gallery or camera)..</p>
  
  <p>I am trying to achieve this via retrofit2. 
  trying some methods from Internet... but i can't get the right way to done it</p>
  
  <p>new in retrofit2. so I cant done this. </p>
  
  <blockquote>
    <p>How to Create retrofit2 interface  and handle the response.. 
    please help</p>
    
    <p>Edit My Try</p>
  </blockquote>
  
  <p>Code in Activity</p>
  
  <pre><code>  ProofAPI service =  retrofit.create(ProofAPI.class);
          File file=new File(sdCard.getAbsolutePath()+fNameAd);
          MultipartBody.Part filePart = MultipartBody.Part.createFormData("proof", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
  
   HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
          map.put("userId", user_id);
          map.put("proofDocId", idproofno);
          map.put("proofFilename", proofFilename);
          map.put("docType", docType);
      Call&lt;ProofResp&gt; call = service.uploadFileWithPartMap(map,filePart);
          call.enqueue(new Callback&lt;ProofResp&gt;() {
              @Override
              public void onResponse(Call&lt;ProofResp&gt; call, Response&lt;ProofResp&gt; response) {
                  Toast.makeText(getApplicationContext(),response.body().getMessage(),Toast.LENGTH_SHORT).show();
              }
  
              @Override
              public void onFailure(Call&lt;ProofResp&gt; call, Throwable t) {
                  Toast.makeText(getApplicationContext(),"fjkds",Toast.LENGTH_SHORT).show();
              }
          });
  </code></pre>
  
  <blockquote>
    <p>Retofit2 Interface -> ProofAPI </p>
  </blockquote>
  
  <pre><code>@Multipart
      @POST("rest-proof-upload")
      Call&lt;ProofResp&gt; uploadFileWithPartMap(
              @PartMap() Map&lt;String, String&gt; partMap,
              @Part MultipartBody.Part file
      );
  </code></pre>
  
  <blockquote>
    <p>and I get the failure message. Is this the right way .. 
    Anyone please explain the correct way to achive it. </p>
  </blockquote>