title: Sending image file with retrofit 2
body: <p>I am trying to upload an image to our project's server using Retrofit 2</p>
  
  <p>The image is picked through an image picking activity and seems to work since the file (image) can be displayed using Picasso.</p>
  
  <p>Retrofit succeeds however the server doesn't seem to get the file.
  Here is the server side part.</p>
  
  <pre><code>func (c *gin.Context) {
     file, header , err := c.Request.FormFile("profileImage")
     // err = http: no such file
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/pKzhB.png" rel="nofollow">Sever side error message</a></p>
  
  <p>Even the RequestBody prints coherent information when I tested it (size, image type...)</p>
  
  <p><strong>Service :</strong> </p>
  
  <pre><code>@Multipart
  @PATCH("/user/profileImage")
  Call&lt;ResponseBody&gt; modifyUserImage(@Part("profileImage") RequestBody profileImage, @Part("userID") RequestBody userID);
  </code></pre>
  
  <p>Following code is part of the same Fragment class</p>
  
  <p><strong>Opening image picking activity :</strong></p>
  
  <pre><code>Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
  getIntent.setType("image/*");
  
  Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  pickIntent.setType("image/*");
  
  Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
  chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
  
  startActivityForResult(chooserIntent, 1);
  </code></pre>
  
  <p><strong>On Activity Result:</strong> </p>
  
  <pre><code>    @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (resultCode == Activity.RESULT_OK &amp;&amp; requestCode == 1) {
          // process the result
          Uri selectedImage = data.getData();
          String wholeID = DocumentsContract.getDocumentId(selectedImage);
          String id = wholeID.split(":")[1];
          String[] column = {MediaStore.Images.Media.DATA};
          String sel = MediaStore.Images.Media._ID + "=?";
          Cursor cursor = getActivity().getContentResolver().
                  query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                          column, sel, new String[]{id}, null);
          String filePath = "";
          int columnIndex = cursor.getColumnIndex(column[0]);
          if (cursor.moveToFirst()) {
              filePath = cursor.getString(columnIndex);
          }
          cursor.close();
  
          file = new File(filePath);
          Picasso
                  .with(getActivity().getApplicationContext())
                  .load(file)
                  .into(civ_userProfilePicture);
      }
  }
  </code></pre>
  
  <p><strong>Request :</strong></p>
  
  <pre><code>Call&lt;ResponseBody&gt; call = ServiceSingelton.getmInstance().getService()
                          .modifyUserImage(RequestBody.create(MediaType.parse("image/*"), file),
                                           RequestBody.create(MediaType.parse("text/plain"), ServiceSingelton.getmInstance().getUserID()));
  
  call.enqueue(new Callback&lt;ResponseBody&gt;() {
      @Override
      public void onResponse(Call&lt;ResponseBody&gt; call, Response&lt;ResponseBody&gt; response) {
          if (response.code() == 200) {
              Log.d("RETROFIT SUCCESS", "Pic should be sent");
          } else {
              Log.d("RETROFIT SUCCESS", "Error code received modifying user");
          }
      }
  
      @Override
      public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
          Log.d("RETROFIT ERROR", t.getMessage());
      }
  });
  </code></pre>