0

Case:

I would like to upload the image byte array with defining the type as image/ png. When it comes to execution in practice, I get the image from my Google Photo and converted as octet-stream

When I try to use Picasso / Glide library to extract the base64 string. it cannot work. I want to find out the way to generate the proper base64 string but it goes in vain and found an exception: bad base64 String.

Would you please tell me the way to convert the image to a proper base64 string and decode an image successfully?

I save the selected image to save as file called avatar.png.

Here is my code to convert From file to byteArray :

  fun convertFileToBase64 (file : File)  : ByteArray{
    val byteArray = IOUtils.toByteArray(bitmap)
    return byteArray
}

Here is my code to convert the base64 string to image using Glide

user.avatar is a base64 string 
             Glide.with(this).asBitmap().load(user.avatar).apply(RequestOptions().placeholder(R.drawable.my_icon).fitCenter()).into(
                     profile_image
             )
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

0 Answers0