title: Could not be able to get file from uri
body: <p>I have a simple scenario, I have to select a file from Internal or external storage and upload to a Server using service.</p>
  
  <p>Opening file chooser in this way</p>
  
  <pre><code>case R.id.action_cv: {
  
      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      intent.setType("*/*");
      startActivityForResult(Intent.createChooser(intent, null), Constant.REQUEST_CODE_OPEN);
  
      break;
  }
  </code></pre>
  
  <p>In <code>onActivityResult()</code> I get file</p>
  
  <pre><code>if (requestCode == Constant.REQUEST_CODE_OPEN) {
      if (resultCode == RESULT_OK &amp;&amp; null != data) {
  
          Uri fileUri = data.getData();
  
          if (Utils.validateFileType(Utils.getMimeType(UserProfileActivity.this, fileUri))){
              Log.e("File", fileUri.toString());
              uploadFile(fileUri.toString());
          } else {
              FutureSmileToast.getInstance()
                      .showToast(getApplicationContext(), "File type is not supported", SuperToast.Background.RED);
          }
  
      }
  }
  </code></pre>
  
  <p>It shows</p>
  
  <pre><code>E/File: content://com.android.externalstorage.documents/document/6158-1118%3Asome_file.txt
  </code></pre>
  
  <p>Now the issue is in <code>uploadFile()</code> method which is</p>
  
  <pre><code>private void uploadFile(String filePath) {
  
      File file = new File(filePath);
  
      String fileNameString = System.currentTimeMillis() + file.getName();
  
      // Parsing any Media type file
      RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
      MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("cvfile", fileNameString, requestBody);
      RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());
  
      Call&lt;ServerResponse&gt; call = mRestManager.getApiService().uploadCVFile(fileToUpload, filename);
      call.enqueue(new Callback&lt;ServerResponse&gt;() {
          @Override
          public void onResponse(Call&lt;ServerResponse&gt; call, Response&lt;ServerResponse&gt; response) {
  
              if (null != response.body()) {
                  serverResponse = response.body();
                  if (serverResponse.getSuccess()) {
  
                      //Further proccesing 
  
                  } else {
                      FutureSmileToast.getInstance()
                              .showToast(getApplicationContext(), serverResponse.getMessage(), SuperToast.Background.RED);
  
                  }
              } else {
                  //
              }
              dialog.dismiss();
          }
  
          @Override
          public void onFailure(Call&lt;ServerResponse&gt; call, Throwable t) {
              t.printStackTrace();
              FutureSmileToast.getInstance()
                      .showToast(getApplicationContext(), "Failed to upload CV", SuperToast.Background.RED);
          }
      });
  } // CV upload
  </code></pre>
  
  <p>This method gives me <strong>Exception</strong></p>
  
  <pre><code>08-11 10:46:35.819 27328-27328/pk.futuresmile W/System.err: java.io.FileNotFoundException: content:/com.android.externalstorage.documents/document/6158-1118%3Asome_file.txt: open failed: ENOENT (No such file or directory)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:496)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:76)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okio.Okio.source(Okio.java:166)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.RequestBody$3.writeTo(RequestBody.java:117)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.java:171)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.MultipartBody.writeTo(MultipartBody.java:113)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:189)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err:     at java.lang.Thread.run(Thread.java:818)
  08-11 10:46:35.823 27328-27328/pk.futuresmile W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
  08-11 10:46:35.824 27328-27328/pk.futuresmile W/System.err:     at libcore.io.Posix.open(Native Method)
  08-11 10:46:35.824 27328-27328/pk.futuresmile W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
  08-11 10:46:35.824 27328-27328/pk.futuresmile W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:482)
  08-11 10:46:35.824 27328-27328/pk.futuresmile W/System.err:     ... 14 more
  </code></pre>
  
  <p>How can I get file from URI and resolve the issue which causes exception?</p>