Reputation: 185
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!
Upvotes: 3
Views: 3779
Reputation: 38976
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())
or alert(e.name + ": " + e.message)
Upvotes: 4