I'm trying to encode an image to base64 and send it to a server. When I retrieve the image all it shows is blank.
The code I'm using to encode it is this:
encodeImageUri = function(imageUri) { var c = document.createElement('canvas'); var ctx = c.getContext("2d"); var img = new Image(); img.onload = function() { c.width = this.width; c.height = this.height; ctx.drawImage(img, 0, 0); }; img.src = imageUri; var dataURL = c.toDataURL("image/jpeg"); return dataURL.slice(22, dataURL.length); } Taken from: Using PhoneGap, How to get base64 image data of the photo chosen from photo library in iPhone