javascript - HTML5 drag and drop for directory upload using local htnl5 file -
this question has answer here:
i have problem: following code perfeclty works http server, not local html5 file (file:///).
any idea why? suggestion allow file drag , drop directory upload?
css:
#drop_zone { font-size: 30px; text-align: center; width: 100%; height: 200px; border: 1px solid black; }
html:
<div id="drop_zone">drop files here</div>
javascript:
function error(e) { console.log('error'); console.log(e); } function error_from_readentries(e) { console.log('error_from_readentries'); console.log(e); } function traversefiletree(item, path) { path = path || ""; if (item.isfile) { // file item.file(function(file) { console.log("file: " + path + file.name); }, error); } else if (item.isdirectory) { // folder contents var dirreader = item.createreader(); dirreader.readentries(function(entries) { (var i=0; i<entries.length; i++) { traversefiletree(entries[i], path + item.name + "/") } }, error_from_readentries); } } function handlefileselect(evt) { evt.stoppropagation(); evt.preventdefault(); var items = evt.datatransfer.items; (var = 0; < items.length; i++) { var item = items[i].webkitgetasentry(); if (item) { traversefiletree(item); } } } function handledragover(evt) { evt.stoppropagation(); evt.preventdefault(); evt.datatransfer.dropeffect = 'copy'; } //setup dnd listeners. var dropzone = document.getelementbyid('drop_zone'); dropzone.addeventlistener('dragover', handledragover, false); dropzone.addeventlistener('drop', handlefileselect, false);
thanks lot!
why: looks readentries raises error when using file:// protocol. bug in webkit or chrome. suggestion: unfortunately no.
i using chrome (version 28.0.1500.95)
Comments
Post a Comment