I have a drop zone where I want to detect whether the dragged item is a folder or file. In chrome I achieved this by using
for (var i = 0; i < nrOfFiles; i++) {
var entry = e.originalEvent.dataTransfer.items[i].webkitGetAsEntry();
if (entry.isDirectory) {
//folder detection
}
In firefox it is not possible to use the above solution(webkit) and after spending many hours trying to solve this I came up with the following solutions (and failed)
I check whether the dragged item has no type and no size as below and in most cases it is working as expected. From what I've read this is not efficient and not successful all the times as some files may not have file extension so I try to read file as binary string(readAsBinaryString) or readAsArrayBuffer with FileReader API and catch the exception in case the item is not readable but the exception is never thrown.
var files = e.originalEvent.dataTransfer.files;
for (var i = 0; i < nrOfFiles; i++) {
if (files[i].size === 0 && files[i].type==="") {
try{
var reader = new FileReader();
reader.readAsBinaryString(files[i]);
}catch(e){
//folder detection ?
}
}}
In the following solution i am trying to use mozGetDataAt which is the corresponding webkitGetAsEntry (??? Not 100% about this please correct me if i am wrong) but i am getting a security exception.
var entry = e.originalEvent.dataTransfer.mozGetDataAt("application/x-moz-file",i);
if (entry.isDirectory) { //not even reaching this statement. idk if isDirectory is applicable to entry
//folder detection?
}
And the exception is :
Permission denied for http://localhost:8080 to create wrapper for object of class UnnamedClass
Is there actually a way to do this in firefox? I do not want to rely on third party libraries or server side processing if possible. Any suggestions-comments would be much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…