java.lang.IllegalArgumentException: bad base-64 when decrypting image

Atlas_Gondal :

I am selecting an image using Jsoup parser

Elements images = document.select("img");
String src = images.attr("src");

then using this code to get rid off data:image/jpg;base64

pureImageSrc = imageSrc.substring(imageSrc.indexOf(",") + 1);

Now I have correct base 64 string (i guess) which starts and ends like

/9j/4AAQSkZJRgABAQEASABIAAD/4Vl6RXhpZgAAT...............lbRIluL+9/56L+VFOoqhH/2Q==

finally, I am decoding it and setting inside an image view

byte[] decodedString = Base64.decode(pureImageSrc, Base64.URL_SAFE);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);

But getting this exception: java.lang.IllegalArgumentException: bad base-64 What's missing in this?

Ryan :

You are decoding with the flag Base64.URL_SAFE which uses - and _ in place of + and /, your base64 string includes /. Try changing the flag to Base64.DEFAULT

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=472754&siteId=1