Java.lang.IllegalArgumentException: bad base-64 in android

I am developing an application that stores user records as a profile.

Where am I taking an image as input and then converting it to base64 string using Android built in transform function.

byte[] b = baos.toByteArray();
final String imageText = Base64.encodeToString(b,Base64.URL_SAFE|Base64.No_WRAP);

      

and send it to server using PHP code and store it in MySQL DB

MySQL Server

Engine is "MyISAM"

column type "text"

column collation "utf8_general_ci"

      

Then it extracts using PHP as XML.

On Android I am parsing XML and decoding an encoded string.

like this

byte [] decodedByte = Base64.decode (String, Base64.URL_SAFE | Base64.No_WRAP); b = BitmapFactory.decodeByteArray (decodedByte, 0, decodedByte.length);

But sometimes it works perfect, but sometimes I get

java.lang.IllegalArgumentException: bad base-64
at android.util.Base64.decode(Base64.java:161)
at android.util.Base64.decode(Base64.java:136)
at android.util.Base64.decode(Base64.java:118)
at... 

      

Please help me, I am new to android.

thank

+3


source to share





All Articles