i have this function that save an uploaded image and display it to the user:
private suspend fun uploadImage222(token: String?) {
if (selectedImageUri == null) {
return
}
val parcelFileDescriptor =
context?.getContentResolver()?.openFileDescriptor(selectedImageUri!!, "r", null) ?: return
val inputStream = FileInputStream(parcelFileDescriptor.fileDescriptor)
var file = File(context?.cacheDir, context?.getContentResolver()?.getFileName(selectedImageUri!!))
val outputStream = FileOutputStream(file)
inputStream.copyTo(outputStream)
file = Compressor.compress(requireContext(), file) {
resolution(150, 150)
quality(100)
format(Bitmap.CompressFormat.JPEG)
size(400_152) // 2 MB
}
val requestFile = file.asRequestBody("image/jpeg".toMediaTypeOrNull())
val body: MultipartBody.Part = MultipartBody.Part.createFormData("file",
"fileany", requestFile)
val updateAvatarUser99 = uploadInterface.createNote().updateAvatarNotes(
"URL",
token,
body
)
updateAvatarUser99.enqueue(object : Callback<String> {
override fun onResponse(call: Call<String>, response: Response<String>) {
if (response.isSuccessful) {
if (response.body()?.equals(null) == true) {
} else {
imageurlllll = response.body().toString()
}
}
}
override fun onFailure(call: Call<String>, t: Throwable?) {
}
})
}
the function is working perfectly, i want to save this value:
imageurlllll = response.body().toString()
and i want to use the saved value in different fragment, what is the best way to achieve this?