ACTION_PICK Image Picker Returns Diffrent Uri Formats
Solution 1:
There is no requirement for the DATA
column of MediaStore
to give you a filesystem path that you can use. For example, the image might be on removable storage on Android 4.4+, which the MediaStore
can access, but you cannot. MediaStore
can also have in its index images that are not local to the device, but are from services like Google Photos (so I've been told).
So, your first step is to get rid of getImagePath()
, as it will be unreliable.
The simplest and most performant solution is to find a way to "compress the images and [do] a multipart image upload on the server" without filesystem access. For example, you have access to an InputStream
via openInputStream()
on ContentResolver
, and that will work for both types of Uri
shown in your question. Find some way to do your work using that InputStream
.
If you determine that this is not possible, you will need to get that InputStream
anyway and make a local copy of the content (e.g., in getCacheDir()
). Then, use your local copy, deleting it when you are done.
Post a Comment for "ACTION_PICK Image Picker Returns Diffrent Uri Formats"