Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does HTML5 allow drag-drop upload of folders or a folder tree?

I haven't seen any examples that do this. Is this not allowed in the API spec?

I am searching for an easy drag-drop solution for uploading an entire folder tree of photos.

like image 337
michael Avatar asked Aug 28 '10 08:08

michael


People also ask

How do I drag and drop files into folders?

To drag and drop a file or folder, click it with your left mouse button, then, without releasing the button, drag it to the desired location and release the mouse button to drop it. Refer to your Windows help for more information if you haven't used drag and drop.

How do I upload a folder to my browser?

Upload (using the File Browser)Click the Upload icon. Click Upload Files or Upload Folders, depending on which you'd like to do. Select the file(s) or folder you'd like to upload. Note: You can select multiple files for upload by holding the Command or Control key (Mac or Windows, respectively) while selecting files.


Video Answer


1 Answers

It's now possible, thanks to Chrome >= 21.

function traverseFileTree(item, path) {   path = path || "";   if (item.isFile) {     // Get file     item.file(function(file) {       console.log("File:", path + file.name);     });   } else if (item.isDirectory) {     // Get folder contents     var dirReader = item.createReader();     dirReader.readEntries(function(entries) {       for (var i=0; i<entries.length; i++) {         traverseFileTree(entries[i], path + item.name + "/");       }     });   } }  dropArea.addEventListener("drop", function(event) {   event.preventDefault();    var items = event.dataTransfer.items;   for (var i=0; i<items.length; i++) {     // webkitGetAsEntry is where the magic happens     var item = items[i].webkitGetAsEntry();     if (item) {       traverseFileTree(item);     }   } }, false); 

More info: https://protonet.info/blog/html5-experiment-drag-drop-of-folders/

like image 57
Christopher Blum Avatar answered Oct 23 '22 13:10

Christopher Blum