I am selecting a image from my gallery on an Android device. The image is returned as a file-uri and I use the filereader to convert the file-uri to a base64 string which I can use to send to the server and also display the image in my app. Problem is that when I try to display the image, I only get a blank picture. The same thing if I try to decode the base64 string, the image is not recognized as an image at all. Function that encodes the file-uri:
encodeImageToBase64: function(imageURI){
var fileReader = new FileReader();
var blob = new Blob([imageURI], { type: 'image/jpeg'});
var result = {};
fileReader.onloadend = function(){
result = fileReaders.result.split(',')[1];
console.log("Result: " + result);
}
fileReader.readAsDataURL(blob);
}
The string I get as a result is as short as ZmlsZTovLy9kYXRhL2RhdGEvbm8uY2Fyd2ViLm1vYmlsZS9jYWNoZS90bXBfSU1HXzIwMTUxMTI3XzA0MjEyNjE2MDg5NDU4ODYuanBn
. When I take a picture with my app I get a dataURL which is much larger, so I am wondering if I am doing this encoding the wrong way or am I missing something here? Any help to point me in the right direction is much appreciated :)