WICG / entries-api

Spec defining browser support for file/directory upload by drag-and-drop
https://wicg.github.io/entries-api/
Other
41 stars 9 forks source link

FileSystemDirectoryReader.readEntries() results with EncodingError #36

Closed vasicek58 closed 4 years ago

vasicek58 commented 4 years ago

When I try the basic example that would process a directory tree and print the name of the items in it, and run it in Chrome (version 81.0.4044.138), I get the following error in readEntries:

DOMException: A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.

It seems to work well in Firefox and Edge. Do you know what is the problem?

function readFiles(item) {

   console.log(item.name);

   if (item.isDirectory) {
    let directoryReader = item.createReader();

    directoryReader.readEntries(entries =>  {
        entries.forEach(function(entry) {
          readFiles(entry);
        });
    }, error => console.error(error));
    }
}

dropzone.addEventListener("drop", function(event) {
  let items = event.dataTransfer.items;

  event.preventDefault();

  for (let i=0; i<items.length; i++) {
    let item = items[i].webkitGetAsEntry();

    if (item) {
        readFiles(item);
    }
  }
}, false);

dropzone.addEventListener("dragover", function(event) {
    event.preventDefault();
}, false);
inexorabletash commented 4 years ago

You should file a bug against Chrome - use https://new.crbug.com

FYI: The reason you get EncodingError rather than something more meaningful is just weirdness in Chrome's implementation where internally there are file system URLs being used to reference these items; if FS URL can't be resolved for some reason an EncodingError ends up surfacing. https://crbug.com/608060 has a similar reason for the silly error type here.

inexorabletash commented 4 years ago

Be sure to include details on the OS and what files you're dropping. I just tried on macOS with a pretty large tree and didn't hit any exceptions. Closing since this is an implementation issue, not a spec issue.

vasicek58 commented 4 years ago

It seems like it's a Windows issue for some reason, I asked a friend of mine to test it on macOS and it went fine as well. Thanks for the fast reaction and all the info!

inexorabletash commented 4 years ago

Thanks @vasicek58 ! If you drop the crbug link here I'll try to get it looked at.

vasicek58 commented 4 years ago

Great, thank you: https://crbug.com/1084223

inexorabletash commented 4 years ago

For posterity: the problem only arises in Chrome if the page is hosted at file:// rather than an HTTP origin. More details in the Chrome bug.