I am using the FileSystemAPI window.showDirectoryPicker() to open a directory which is returning a handle to that directory & by using that I can traverse all the files present in that directory.
const dropArea = document.getElementById("drop_zone");
dropArea.onclick = async (evt) => {
const dirHandle = await window.showDirectoryPicker();
// Next lines of code using dirHandle
};
Above piece of code working fine when use clicking on the button which is prompting the user to chose a directory. I want to achieve the same functionality with the drag & drop as well, means instead of clicking & choosing a directory user can drop a directory.
Followed below link but it didn't work for me.
I will appreciate for any help or input on this. Thank you!
The HTML Drag and Drop interfaces enable web applications to accept dragged and dropped files on a web page. During a drag and drop operation, dragged file and directory items are associated with file entries and directory entries respectively. The
DataTransferItem.getAsFileSystemHandle()method returns a promise with aFileSystemFileHandleobject if the dragged item is a file, and a promise with aFileSystemDirectoryHandleobject if the dragged item is a directory. The listing below shows this in action. Note that the Drag and Drop interface'sDataTransferItem.kindwill be"file"for both files and directories, whereas the File System Access API'sFileSystemHandle.kindwill be"file"for files and"directory"for directories.