This snippet of javascript code creates an image upload button and displays the uploaded image:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#target').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
You can view the full jsfiddle example here.
Although this code works perfectly on most mobile browsers, it encounters a problem specifically with the stock Android browser. Images fail to load if they are stored remotely, such as those from synced Facebook or Picasa accounts. While FileReader is designed for local files, other mobile browsers like Chrome, Opera, and Firefox have no issues with loading remote images.
After checking the FileReader error code, it seems that images from Facebook/Picasa return a NOT_FOUND_ERR: https://developer.mozilla.org/en-US/docs/Web/API/FileError
This issue seems unique to the stock Android browser, as it works fine with local files and camera-captured images, but fails to load remote Facebook/Picasa images, showing icons instead of the actual photos. This anomaly has been observed on Android versions 4.3 and 4.4.
Although similar issues have been discussed online, such as this thread on Stack Overflow: Issue with stock Browser picking photos from Gallery
The issue seems to be related to the inability of FileReader to read remote files, but the fact that it works on other mobile browsers raises questions about the specific compatibility of the stock Android browser.