Это потому, что без f компилятор увидит это как double
не float
Я сделал много тестов, поэтому я получил решение, как я покажу в коде ниже, но если вы знаете лучшее решение, покажите мне.
private fun postImage() {
user_register_button.setOnClickListener {
if (selectedImage != null) {
var imageFile = File(baseContext.cacheDir, "${System.currentTimeMillis()}")
imageFile.createNewFile()
var arrayOutputStream = ByteArrayOutputStream()
getBitmapFromUri(selectedImage).compress(Bitmap.CompressFormat.JPEG, 100, arrayOutputStream)
var outputStream = FileOutputStream(imageFile)
outputStream.write(arrayOutputStream.toByteArray())
outputStream.flush()
outputStream.close()
var descriptionBody = RequestBody.create(MediaType.parse("image/*"), imageFile)
val imagePart = MultipartBody.Part.createFormData("file", "${System.currentTimeMillis()}", descriptionBody)
ImageRequest(getString(R.string.base_url_file_upload)).postImageFile(
image = imagePart, delegate = object : Delegate<ResponseBody> {
override fun onSuccessFull(isSuccessFull: Boolean, response: ResponseBody?, message: String?) {
if (isSuccessFull) {
Log.i("ResponseBody", response.toString())
} else {
Log.i("ResponseError", message)
}
}
override fun onFailure(exception: Throwable) {
Log.i("Error", exception.message)
exception.printStackTrace()
}
})
}
}
}
@Throws(IOException::class)
private fun getBitmapFromUri(uri: Uri): Bitmap {
val parcelFileDescriptor = contentResolver.openFileDescriptor(uri, "r")
val fileDescriptor = parcelFileDescriptor.fileDescriptor
val image = BitmapFactory.decodeFileDescriptor(fileDescriptor)
parcelFileDescriptor.close()
return image
}