Using PhoneGap(Cordova), Am trying to get base64 image data of the photo chosen from the photo library.
I could do that.. when the photo is captured from camera, With the below snippet of code in Cordova.
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
But, what should i do to get the base64 image data when the photo gets chosen from library?
Try this one: https://github.com/brianvandelden/acato-service-image. It uses the imagePicker.git cordova plugin. With a function to get the imageData from selected pictures.
Its the good way to get image in base64 but when is show base64 string returned by this function. It display me a white image. My code is as follows
You can use this plugin to get you the base64 encoding of the image, it uses js code for iOS, but in case of android it uses native code to handle android versions lower then v.3 because android versions lower then 3 are not handle toDataUrl functionality
I have no solution in PhoneGap for this. So all I need is the base64 format of the image which has been chosen by user from their photo library. So I placed that image on canvas and toDataUrl() gave me the very format :-)
You just need to tell it to pick from the photo library:
Please be aware that loading a large base 64 encoded image may just cause and out of memory error in your app. Wherever possible use the FILE_URI to get your photo.
Try this out.