title: Android - Uploading Image with Multipart Retrofit Failed or Crash
body: <p>I try to make an upload image with Retrofit Mulitpart Android. But I still get my app error.</p>
  
  <p>This is how to get the image</p>
  
  <pre><code> private final int SELECT_PHOTO = 1;
  
        private void startGallery() {
          Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
          photoPickerIntent.setType("image/png");
          startActivityForResult(photoPickerIntent, SELECT_PHOTO);
      }
  </code></pre>
  
  <p>this is the onActivityResult and the way i request to upload the image</p>
  
  <pre><code> @Override
  public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
      super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
      switch (requestCode) {
          case SELECT_PHOTO:
              if (resultCode == RESULT_OK) {
                  selectedImage = imageReturnedIntent.getData();
                  File file = new File(selectedImage.getPath());
  
                  RequestBody reqFile = RequestBody.create(okhttp3.MediaType.parse("image/png"), file);
  
                  // MultipartBody.Part is used to send also the actual file name
                  MultipartBody.Part body = MultipartBody.Part.createFormData("DocTyp01", file.getName(), reqFile);
  
                  getApi().uploadByCustomer(PrefHelper.getString(PrefKey.TOKEN), "DocTyp01", body)
                          .observeOn(AndroidSchedulers.mainThread())
                          .subscribeOn(Schedulers.io())
                          .subscribe(new Observer&lt;GenericResponse&gt;() {
                              @Override
                              public void onCompleted() {
  
                              }
  
                              @Override
                              public void onError(Throwable e) {
                                 dismissProgressDialog();
                                  Timber.e(e.getMessage());
                              }
  
                              @Override
                              public void onNext(GenericResponse response) {
                              dismissProgressDialog();
                                  if (response.getCode() == 0) {
                                   showSuccessDialog("Saving success", false);
                                  }
  
                              }
                          });
              }
  
  
              }
      }
  </code></pre>
  
  <p>this is the API Service </p>
  
  <pre><code>    @Multipart
      @POST(PORTAL_URL + "customerDocument/uploadByCustomer")
      Observable&lt;GenericResponse&gt; uploadByCustomer(@Part("token") String token,
                                                   @Part("type") String type,
                                                   @Part MultipartBody.Part requestBodyFile);
  </code></pre>
  
  <p>And Sometimes the log didn't show me the error, and also I got no response from API, it makes me hard to find the error. Please, help me to solve this. Thanks.</p>