I am trying to post an Image into the server, I manage to get the Image URI and Bitmap and want to transform it into a File so I can post it using Retrofit. but I get this error
FileNotFoundException: /document/image:29467: open failed: ENOENT (No such file or directory)
That is the Code I am using to get he URI
var imageUri by remember { mutableStateOf<Uri?>(null) }
val context = LocalContext.current
val bitmap = remember { mutableStateOf<Bitmap?>(null) }
imageUri?.let {
if (Build.VERSION.SDK_INT < 28) {
bitmap.value = MediaStore.Images
.Media.getBitmap(context.contentResolver, it)
} else {
val source = ImageDecoder.createSource(context.contentResolver, it)
bitmap.value = ImageDecoder.decodeBitmap(source)
}
}
val file = File(imageUri!!.path)
and This is how I transform it into a request body in my Viewmodel
val response = serviece.addYourBrand(name,
image = MultipartBody.Part.createFormData("image", file.name, file.asRequestBody()),
categoryIDFormBody).body()
and that's my Service Interface
@Multipart
@POST("brand")
suspend fun addYourBrand (
@Part("name") name : RequestBody,
@Part image : MultipartBody.Part,
@Part("category_id[]") categoryId : RequestBody
) : Response<BaseResponse>