title: how to choose any type of file and upload it to server?
body: <p>I'm trying to choose any type of files like <code>.pdf</code> or <code>.doc</code> and ect and then upload it to server with <code>retrofit</code> library.
  I'm able to choose image and video and music from my files and send it easily to server. but in api 19 and above, I can't have direct access to other files! I tried this way :</p>
  
  <pre><code>    private InputStream getInputStreamForVirtualFile(Uri uri, String mimeTypeFilter)
          throws IOException {
  
      ContentResolver resolver = getContentResolver();
  
      String[] openableMimeTypes = resolver.getStreamTypes(uri, mimeTypeFilter);
  
      if (openableMimeTypes == null || openableMimeTypes.length &lt; 1) {
          throw new FileNotFoundException();
      }
  
      return resolver
              .openTypedAssetFileDescriptor(uri, openableMimeTypes[0], null)
              .createInputStream();
  }
  </code></pre>
  
  <p>this code give me <code>InputStream</code> of the file and for sending it to server with retrofit I figured to create a copy of my file, and then use that file to send it , my code is :</p>
  
  <pre><code>    private File getFile(Uri uri) throws IOException {
      String[] array = uri.getPath().split("/");
      File x = new File(Environment.getExternalStorageDirectory()+ "/" + array[array.length - 1]);
      FileOutputStream fileOutputStream = new FileOutputStream(x);
      InputStream inputStream = getInputStreamForVirtualFile(uri, "*/*");
      byte[] buffer = new byte[4096];
      int n = 0;
      while (-1 != (n = inputStream.read(buffer))) {
          fileOutputStream.write(buffer, 0, n);
      }
      inputStream.close();
      fileOutputStream.close();
      return x;
  }
  </code></pre>
  
  <p>I am not able to send it to server yet, but these code in android 8 gives me the right file , but it android 7, I have this error :</p>
  
  <pre><code>The requested MIME type is not supported.
  </code></pre>
  
  <p>my question is what is the proper way to choose any type of file and send it to server with retrofit?! </p>
  
  <p>and if my way is a rational way to sending any type of file, how can I fix it to support all androids such as android 7 and fix my error!?</p>