DataTransferItem.getAsFileSystemHandle()

Draft: This page is not complete.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The getAsFileSystemHandle() method of the DataTransferItem interface returns a FileSystemFileHandle if the dragged item is a file, or a FileSystemDirectoryHandle if the dragged item is a directory.

Syntax

var handle = DataTransferItem.getAsFileSystemHandle();

Parameters

None.

Return value

A FileSystemFileHandle or FileSystemDirectoryHandle.

Exceptions

None.

Examples

This example uses the getAsFileSystemHandle method to return file handles for dropped items.

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') {
    const entry = await item.getAsFileSystemHandle();
      if (entry.kind === 'file') {
        // run code for if entry is a file
      } else if (entry.kind === 'directory') {
        // run code for is entry is a directory
      }
    }
  }
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
getAsFileSystemHandle
86
86
No
No
72
No
No
No
No
No
No
No

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFileSystemHandle