title: Uploading image by using Retrofit
body: <p>I've been trying to upload an image from my application through API. But I keep getting this as response:</p>
  
  <pre><code>{"error":"&lt;p&gt;You did not select a file to upload.&lt;\/p&gt;"}
  </code></pre>
  
  <p>This is my code:</p>
  
  <p><strong>APIService.java</strong></p>
  
  <pre><code>@Multipart
  @POST("/media/upload.html")
  Call&lt;UploadImg&gt; uploadimage (@Part MultipartBody.Part file);
  </code></pre>
  
  <p><strong>UploadImageActivity.java</strong></p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if(requestCode == REQUEST_CODE &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null &amp;&amp; data.getData() != null){
          Uri uri = data.getData();
          Picasso.with(this).load(uri).fit().into(btn_img_picker);
  
          String imagePath;
  
          if (data.toString().contains("content:")) {
              imagePath = getRealPathFromURI(uri);
          } else if (data.toString().contains("file:")) {
              imagePath = uri.getPath();
          } else {
              imagePath = null;
          }
  
          File file = new File(imagePath);
  
          System.out.println(imagePath);
  
          RequestBody requestFile = RequestBody.create(MediaType.parse("image/*"), file);
  
          MultipartBody.Part body = MultipartBody.Part.createFormData("userfile", file.getName(), requestFile);
  
          System.out.println(file.getName());
  
          Call&lt;UploadImg&gt; call = mAPIService.uploadimage(body);
          call.enqueue(new Callback&lt;UploadImg&gt;() {
              @Override
              public void onResponse(Call&lt;UploadImg&gt; call, Response&lt;UploadImg&gt; response) {
                  System.out.println(response.raw());
              }
  
              @Override
              public void onFailure(Call&lt;UploadImg&gt; call, Throwable t) {
                  System.out.println(t);
              }
          });
      }
  }
  
  public String getRealPathFromURI(Uri contentUri) {
      Cursor cursor = null;
      try {
          String[] proj = {MediaStore.Images.Media.DATA};
          cursor = getContentResolver().query(contentUri, proj, null, null,
                  null);
          int column_index = cursor
                  .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
          cursor.moveToFirst();
          return cursor.getString(column_index);
      } finally {
          if (cursor != null) {
              cursor.close();
          }
      }
  }
  </code></pre>
  
  <p>I have tested sending image in <strong>Postman</strong>'s form-data. I can send a picture from my desktop and received intended response. But I can't do the same with my code in android.</p>
  
  <p>Am I sending the incorrect path format of the image? Currently, variable <code>imagePath</code> has an output like this:</p>
  
  <pre><code>/storage/emulated/0/Download/download.jpg
  </code></pre>
  
  <p>If this is the incorrect path to send, please tell the correct one. Thanks in advance.</p>