Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html 5 FileReader always is error

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!

like image 269
Aidan Avatar asked Sep 29 '26 11:09

Aidan


1 Answers

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)

like image 149
SpliFF Avatar answered Oct 02 '26 00:10

SpliFF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!