WICG / file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
https://wicg.github.io/file-system-access/
Other
669 stars 66 forks source link

All dataTransfer.items is of kind "file"!? #299

Closed jimmywarting closed 3 years ago

jimmywarting commented 3 years ago

Ok, so i saw this example in the spec

elem.addEventListener('dragover', (e) => {
  // Prevent navigation.
  e.preventDefault();
});
elem.addEventListener('drop', async (e) => {
  // Prevent navigation.
  e.preventDefault();

  // Process all of the items.
  for (const item of e.dataTransfer.items) {
    // kind will be 'file' for file/directory entries.
    if (item.kind === 'file') {                                // <----- this will always be true
      const entry = await item.getAsFileSystemHandle();
      if (entry.kind === 'file') {
        handleFileEntry(entry);
      } else if (entry.kind === 'directory') {
        handleDirectoryEntry(entry);
      }
    }
  }
});

I looked further into DataTransfer and found out that whatever you drop file or folder the item.kind is always "file"? why is that?! why isn't it a directory when you drop a folder? Only way to distinguish this is if you do webkitGetAsEntry() and look at that "entry.kind" instead, or getAsFileSystemHandle in this case... is this a bug?

Try it for yourself: drop a folder on this red square: https://jsfiddle.net/sn8bj245/

inexorabletash commented 3 years ago

That's the behavior in all browsers, predating this API.

See: https://wicg.github.io/entries-api/#html-data