Reputation: 77
I've been trying to store images in mysql database by encoding them in a base64 string then passing them to a php script that in turn stores this string in a blob (I also tried text) filed. What happens is the string is sent to the php script as it is, but when stored in the database, its is stored as a completely different string.
Here is how i do it:
Bitmap image = BitmapFactory.decodeFile("/sdcard/photo2.jpg");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteImage = stream.toByteArray();
String s = Base64.encodeToString(byteImage, Base64.NO_WRAP | Base64.URL_SAFE);
And then the string 's' is passed to the php script (correctly as I've checked it) and the script in turn insert it in the database.
This link http://diffchecker.com/kKD4w16C contains how the original encoded string (on the left of the screen) and the string that is stored in the database (on the right of the screen).
Any ideas why this is happening and how to prevent it?
Thanks in advance.
Upvotes: 4
Views: 1773
Reputation: 1810
You dont notice, that u just cut on ~20% of string? Seems like there is limit for your DB field. Something like varchar(255)
and u try to store 1500
length string.
http://tinyurl.com/c2e7hru - see here. I just copy the end of your DB field value and find it in "original" value.
Also, check your encoding.
Upvotes: 2