0

I must upload image file by use retrofit this is Api

@POST("/image")
    suspend fun uploadImage(
        @Body request: UploadImageRequest,
    ): Response<UploadImageResponse>

UploadImageRequest

data class UploadImageRequest(
    @SerializedName("image") val image: String,
)

I implement get image in device storage this is code that get image

private val imageResult = registerForActivityResult(
        StartActivityForResult(),
    ) { result ->
        if (result.resultCode == RESULT_OK) {
            val imageUri = result.data?.data
            imageUri?.let {
                if (Build.VERSION.SDK_INT < 28) {
                    bitmap =
                        MediaStore.Images.Media.getBitmap(this.contentResolver, imageUri)
                } else {
                    val source = ImageDecoder.createSource(this.contentResolver, imageUri)
                    bitmap = ImageDecoder.decodeBitmap(source)
                }
            }
            binding.imageActivityChangeUserInformationUserProfile.setImageBitmap(bitmap)
        }
    }

I don't know how I can upload that image I tried that image to string by use base64 encode but encoding string is too long

I tried create temp image file in device storage. But, changed policy, scoped storage? I couldn't make a new file my app sdk is 33

Tmdhoon2
  • 11
  • 1
  • 3

1 Answers1

0

If you have a file and you want to upload that file then do not first make a bitmap out if it.

Certainly not if you then ask to save that bitmap to file as then you can start over again.

And pdf's and doc's let them convert to bitmap pretty bad.

So just upload the file.

Just the bytes of the file.

blackapps
  • 8,011
  • 2
  • 11
  • 25