I am trying to read a image file, but it never succeeds. The onerror method is always called. Here is my code.
dropZone.addEventListener('drop', function(e)
{
var f = e.dataTransfer.files[0];
if(!f.type.match('image.*'))
{
return;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = handleReaderLoad;
reader.onerror = function(e)
{
alert("it failed")
}
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}, false);
function handleReaderLoad(evt)
{
alert("it worked")
}
This always fails. Any help would be welcome. Thanks!
I think you’ll probably be seeing this issue.
As a general rule you should look more closely at your errors rather than
alert('failed')because the error code will give you a better idea of the issue, eg:alert(e.toString())oralert(e.name + ": " + e.message)