title: How to upload image through retrofit?
body: <p>I have looked through many stackoverflow answers but could not upload image. It used to give me <code>Internal Server Error</code>. Now I found a <a href="https://stackoverflow.com/a/42578987/8051673">solution</a> but it sends a null image to the server. Could you please show me where I am doing wrong.</p>
  
  <p>Here is my <strong>Request CODE</strong>:</p>
  
  <pre><code>@Multipart
  @POST("lostandfound")
  Call&lt;ResponseBody&gt; uploadLostAndFound(@PartMap Map&lt;String, RequestBody&gt; map);
  </code></pre>
  
  <p>And my <strong>CALL</strong>:</p>
  
  <pre><code>    Map&lt;String, RequestBody&gt; map = new HashMap&lt;&gt;();
      map.put("usermail", toRequestBody("mohammad_sed"));
      map.put("content", toRequestBody(content));
      map.put("islost", toRequestBody(String.valueOf(isLost)));
      map.put("wasfound", toRequestBody(foundPlace));
      map.put("tofind", toRequestBody(toFindPlace));
  
      File file = new File(destination);
  
  
      RequestBody reqFile = RequestBody.create(MediaType.parse("image"), file);
      MultipartBody.Part body = MultipartBody.Part.createFormData("upload", file.getName(), reqFile);
      map.put("img", body);
  
      ForumService client = Utils.getBuilder().create(ForumService.class);
      Call&lt;ResponseBody&gt; call = client.uploadLostAndFound(map);
      call.enqueue(new Callback&lt;ResponseBody&gt;() {
          @Override
          public void onResponse(Call&lt;ResponseBody&gt; call, Response&lt;ResponseBody&gt; response) {
              if (response.isSuccessful()) {
                  mProgressDialog.dismiss();
                  // Toast.makeText(getApplicationContext(), "Request created", Toast.LENGTH_SHORT).show();
              } else {
                  mProgressDialog.dismiss();
              }
          }
  
          @Override
          public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
              mProgressDialog.dismiss();
              Toast.makeText(getApplicationContext(), "Failed to upload!", Toast.LENGTH_SHORT).show();
          }
      });
  
      // This method  converts String to RequestBody
      public static RequestBody toRequestBody(String value) {
          RequestBody body = RequestBody.create(MediaType.parse("text/plain"), value);
          return body;
      }
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>@Multipart
  @POST("lostandfound")
  Call&lt;ResponseBody&gt; uploadLostAndFound(@Part MultipartBody.Part photo,
                                        @PartMap Map&lt;String, RequestBody&gt; map);
  </code></pre>
  
  <p>But this way I get <code>Internal server error</code>. 
  <br>Thanks in advance.</p>