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