Create File object from Android content URI

nao

I have a content URI in the form of "content://media/external/images/media/175". I am trying to find the absolute path of the image in question in order to send the file in a request. Is there any way to accomplish this?

CommonsWare

I am trying to find the absolute path of the image

A Uri is not a file. You cannot convert arbitrary Uri values to some filesystem path that you can access. Those Uri values might point to:

  • A file on removable storage
  • A file on internal storage of some other app
  • A file that has not yet been downloaded, but will be downloaded on the fly by the ContentProvider
  • A file that has been encrypted and will be decrypted on the fly by the ContentProvider
  • A BLOB in a database
  • Content that will be generated dynamically, the way this Web page is
  • And so on

in order to send the file in a request

Use a ContentResolver and openInputStream() to get an InputStream to use in your request. If whatever API you are using does not support an InputStream, either:

  • Switch to a better API, or

  • Use that InputStream to make a local file copy on your own internal storage, then use that file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android: Getting a file URI from a content URI?

Get content uri from file path in android

Create a file from a photo URI on Android

How to open a file from Android content URI in NativeScript?

React Native - Get file name from android content uri

Android: How to convert File Uri to Content Uri

Get a Content URI from a File URI?

Create Javascript File/Blob object from image URI

Getting file from content uri for videos taken

Android get EXIF data from content URI

Android Kotlin (beginner) - using File() with Uri returned from ACTION_GET_CONTENT

Read content Uri from File from SharedPreferences and get persistent permission on it

Trying to read Text File from Uri Android

Android open file input stream from uri

Android Content Uri Format

Android: How to create a XML - based file for the data container, read from file/add content

Getting the Absolute File Path from Content URI for searched images

How to download a file in my app from a cloud with a content URI

Is it possible to Get exact file path from content URI?

Permission error when reading file from content uri

How to extract the file name from a file URI and create a link for the same?

How to read object URI (JSON file) from JSON file

Display image from URI with "content://" scheme with Glide on Android Q

How to create a file from PHP echoed content?

How to create file object from URL object

Generate file object from content using javascript

How to convert a content Uri into a File

query file uri with content resolver?

Android create file from drawable