0

I am trying to post image to my webserver. First, I need to convert Uri Image, which I get from Intent Action Pick, into File. So I can put it in Retrofit. But when I am trying to convert Uri into File, I got this error.

java.lang.IllegalArgumentException: Uri lacks 'file' scheme: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F31/ORIGINAL/NONE/image%2Fjpeg/244644339
var chosenImage: Uri? = null

val file = chosenImage!!.toFile()

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && requestCode == 100) {
            mainImageView.setImageURI(data?.data) // handle chosen image
            chosenImage = data?.data
        }
    }

Error happen on variable file. Any help would be appreciated

nabil arta
  • 152
  • 1
  • 3
  • 2
    `need to convert Uri Image, which I get from Intent Action Pick, into File.` No, you dont need that. Read stackoverflow pages to discover what you can do instead. Many thought the same first too. – blackapps Jul 23 '21 at 21:28

0 Answers0