Problem Definition:
I want to select multiple images from mobile gallery and upload it. But before uploading, as soon as the user select images, I want to show preview of images selected. For achieving this, I am using the below code snippet which works perfectly on desktop browser. But, when the same is tried using mobile browser, it doesn't show the preview of images.
I tried by executing the below code as an html file as well as on the "try it yourself" editor which w3schools.com provide. In both cases, it works fine if I am doing it using a desktop browser but doesn't show preview of images if I am using mobile browser.
W3shcools Editor: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
I am using below version of google chrome.
Desktop: 27.0.1453.94 m
Mobile : 27.0.1453.90
Mobile Model: Samsung Galaxy S2
Appreciate any help in this regard.
<!DOCTYPE html>
<html>
<head>
<title>File API - FileReader as Data URL</title>
</head>
<body>
<header>
<h1>File API - FileReader</h1>
</header>
<article>
<label for="files">Select multiple files: </label>
<input id="files" type="file" accept="image/*" multiple/>
<output id="result" />
</article>
</body>
<script>
window.onload = function(){
//Check File API support
if(window.File && window.FileList && window.FileReader)
{
var filesInput = document.getElementById("files");
filesInput.addEventListener("change", function(event){
var files = event.target.files; //FileList object
//console.log(files);
var output = document.getElementById("result");
//console.log(result);
for(var i = 0; i< files.length; i++)
{
var file = files[i];
//Only pics will be allowed
if(!file.type.match('image'))
continue;
var picReader = new FileReader();
picReader.addEventListener("load",function(event){
var picFile = event.target;
console.log(event);
var div = document.createElement("div");
div.innerHTML = "<img class='thumbnail' src='" + picFile.result + "'" +
"title='" + picFile.name +"' width='80' height='80'/>";
console.log(div.innerHTML);
output.insertBefore(div,null);
});
//Read the image
picReader.readAsDataURL(file);
}
});
}
else
{
console.log("Your browser does not support File API");
}
}
</script>
</html>
picReader.addEventListener("load",function(event){}
Checked that by putting alert in every code block. Thanks for the hint. – Anup Jul 12 '13 at 13:28