title: Android having problems while uploading Images using Retrofit multipart?
body: <p>I'm getting the following error while trying to upload an Image to a server using retrofit, the api receives a header authorization token, _method = "put" and image = "imageName.jpg" as parameters, everything else is optional, any help would be appreciated.</p>
  
  <blockquote>
    <p>java.io.FileNotFoundException: /storage/emulated/0/Download/space-wallpaper-21.jpg: open failed: EACCES (Permission denied)</p>
  </blockquote>
  
  <pre><code>userImage.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              galleryIntent.setType("*/*");
              startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
          }
      });
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == RESULT_LOAD_IMG &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
  
          // Get the Image from data
          Uri selectedImage = data.getData();
          String[] filePathColumn = {MediaStore.Images.Media.DATA};
  
          // Get the cursor
          Cursor cursor = getContentResolver().query(selectedImage,
                  filePathColumn, null, null, null);
          // Move to first row
          cursor.moveToFirst();
  
          int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
          imageDecodableString = cursor.getString(columnIndex);
          cursor.close();
  
          StringBuilder stringBuilder = new StringBuilder(AUTHORIZATION);
  
          sharedPreferences = this.getSharedPreferences(getResources().getString(R.string.token), 0);
          stringBuilder.append(sharedPreferences.getString(getResources().getString(R.string.token), ""));
  
          methodMap.put("_method", "PUT");
  
          File file = new File(imageDecodableString);
          RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
          MultipartBody.Part body = MultipartBody.Part.createFormData("image", file.getName(), requestBody);
          //RequestBody name = RequestBody.create(MediaType.parse("text/plain"), "image");
  
          Call&lt;UserInfo&gt; uploadImage = new RestClient(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION).getUserSignUpClient()
                  .postImage(stringBuilder.toString(), methodMap, body);
  
          uploadImage.enqueue(new Callback&lt;UserInfo&gt;() {
              @Override
              public void onResponse(Call&lt;UserInfo&gt; call, Response&lt;UserInfo&gt; response) {
  
                  if (response.isSuccessful()) {
  
                  }
  
              }
  
              @Override
              public void onFailure(Call&lt;UserInfo&gt; call, Throwable t) {
  
                  Toast.makeText(DetailActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  </code></pre>
  
  <p>Interface:</p>
  
  <pre><code>public interface UserSignUpClient {
  
  @POST("account")
  Call&lt;AuthenticationAccountCreationResponse&gt; createAccount(@Body UserSignUp userSignUp);
  
  @Multipart
  @POST("account")
  Call&lt;UserInfo&gt; postImage(@Header("Authorization") String headerValue, @PartMap Map&lt;String, String&gt; map, @Part MultipartBody.Part image);
  }
  </code></pre>
  
  <p>Retrofit Builder Class:</p>
  
  <pre><code>public class RestClient {
  
  private UserSignInClient userSignInClient;
  private UserSignUpClient userSignUpClient;
  private UserInfoClient userInfoClient;
  private UserImageUploadClient userImageUploadClient;
  
  public RestClient(String baseUrlLink){
  
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl(baseUrlLink)
              .addConverterFactory(GsonConverterFactory.create()).build();
  
      if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_TOKEN)){
  
          userSignInClient = retrofit.create(UserSignInClient.class);
      } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION)) {
  
          userSignUpClient = retrofit.create(UserSignUpClient.class);
      } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_USER_INFO)){
  
          userInfoClient = retrofit.create(UserInfoClient.class);
      }
  }
  
  public UserSignInClient getUserSignInClient() {
      return userSignInClient;
  }
  
  public UserSignUpClient getUserSignUpClient() {
      return userSignUpClient;
  }
  
  public UserInfoClient getUserInfoClient() {
      return userInfoClient;
  }
  }
  </code></pre>