I am getting these errors when I am uploading images. The path is storing in database table, But the image folder does not have image.
These are the errors
E/ErrorUtil: Error: /document/primary:DCIM/Camera/20190804_111501.jpg (No such file or directory) W/System.err: java.io.FileNotFoundException: /document/primary:DCIM/Camera/20190804_111501.jpg (No such file or directory)
Here I shared my code.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == Activity.RESULT_OK
&& null != data) {
if(data.getClipData() != null) {
val count = data.getClipData().getItemCount(); //evaluate the count before the for loop --- otherwise, the count is evaluated every loop.
for(i in 0..count-1) {
val imageUri : Uri = data.getClipData().getItemAt(i).uri
// getRealPathFromURI(applicationContext,imageUri)
imageUri.let {
Log.d("imageUri",it.toString())
Log.d("imagePath",it.path)
file = File(it.path)
val jj=Gson()
Log.d("fileIS",jj.toJson(file))
fileType = EnumUtils.FileType.IMAGE.value
val name = file!!.name
Log.d("fimenameis",name)
multipartArray!!.add(MultipartBody.Part.createFormData("files[]", file!!.name, RequestBody.create(MediaType.parse(file!!.path.getMimeType()?: ""), file!!)))
val s = Gson()
Log.d("multipartArray",s.toJson(multipartArray).toString())
}
}
//do something with the image (save it to some directory or whatever you need to do with it here)
} else if(data.getData() != null) {
val imagePath = data.getData().getPath();
fileType = EnumUtils.FileType.IMAGE.value
file = File(imagePath)
multipartArray!!.add(MultipartBody.Part.createFormData("files[]", file!!.name, RequestBody.create(MediaType.parse(file!!.path.getMimeType()?: ""), file!!)))
Log.d("imagePath",imagePath.toString())
//do something with the image (save it to some directory or whatever you need to do with it here)
}
}