Mahbubur Rahman Khan Mahbubur Rahman Khan -5 years ago 203
Javascript Question

decode base64 image fail after retrive from database

May it easy. But i can't figure it out.
I am using cordova camera plugin which give me direct base64 data like following.., onFail, {quality: 50,
destinationType: Camera.DestinationType.DATA_URL});

function onSuccess(imageData) {
$('#userFullProfileImage').attr('src', "data:image/jpeg;base64," + imageData);

It is working. Because it shows me the image after set source of userFullProfileImage. So encoding is correct.

Now, i am trying to save imageData in mysql and retrieve it via ajax.

After retrieve i match several line and found no mistake. imageData before save and imageData after retrieve seems to me same ( But save data omit all + character)

Retrieved image data can't decode. I use online base64 decoder too. But no hope. May be missing + character is for this reason.

I have checked all other character, line by line, both of imageData are same.

So now help me, which could be the possible reasons in my case.

Answer Source

My problem was during send image data through ajax.

encodeURIComponent(imageData); //This solve my problem.

Encoded data is now safely save in database.

After retrieve from encoded data from database i have just used another function.

decodeURIComponent(encodedData); //same of imageData
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download