0

What is the best/recommended method to upload PDF (or other "doc" files) from File Chooser? Since there's many deprecated method in Android such as Environment.getExternalStorageDirectory() MediaStore.Files.FileColumns.DATA etc. It makes us harder to get the File reference to it.

What i do now is get uri from onActivityResult, copy the content to private folder, and use the private-copied File to upload to server. But i think that's too expensive

Is there any better-recommended-bugfree method to do?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
zihadrizkyef
  • 1,849
  • 3
  • 23
  • 46
  • 1
    no need to add the android-studio tag, considering that you're not asking about the IDE itself – a_local_nobody Aug 02 '21 at 12:02
  • 1
    Use one of the `InputStreamRequestBody` implementations floating around, such as [this one](https://commonsware.com/blog/2020/07/05/multipart-upload-okttp-uri.html), [this one](https://cketti.de/2020/05/23/content-uris-and-okhttp/), or [this one](https://github.com/square/okhttp/issues/3585#issuecomment-327319196). – CommonsWare Aug 02 '21 at 12:28

0 Answers0