I am trying to compress a list of Images in Kotlin using zelory Compressor before uploading with multipartform data.
fun uploadImages()
{
progressUpdate.postValue(ProgressUpdate._WORKING)
viewModelScope.launch {
val params = LinkedHashMap<String, RequestBody>()
repo.listUri.forEachIndexed {index,file->
try {
val compressedImageFile = Compressor.compress(context, File(file.path)) {
quality(50)
}
params["myFiles$index\"; filename= \" + $index.jpeg"] = InputStreamRequestBody(context, Uri.fromFile(compressedImageFile))
}catch (e: Exception) {
print("Error!")
}
}
val response = repo.apiInterface?.uploadUri(previousRecNoForPod,"pod", "android", params)
response?.enqueue(fileUploadResponse)
}
}
I am having some issues with the file / path stuff. I believe the error is either
File(file.path) or Uri.fromFile(compressedImageFile))
Does anyone have any suggestions as to why I am having this issue?