I have an element that allows for dropping things on it like so
var div = document.createElement("div");
div.addEventListener("drop", (e)=>{
e.preventDefault();
if (!(("dataTransfer" in e) && ("files" in e.dataTransfer))) return;
for (var i = 0; i < e.dataTransfer.files.length; i++) {
var file = e.dataTransfer.files[i];
// magical check whether the file is a folder?
upload_file(file);
}
});
Problem is, folders show up in the FileList object just the same and they seem to be indisginguishable from files up until the point where you try to read them using FileReader.
They have a size which seems to be exactly the cluster size of whatever drive the file is from, they have no type but same is true for any uncommon file extension. When you try to read them with FileReader, the onload even is simply never raised.
I could try and do a test read with some kind of timeout mechanism in place to detect that its not a file but this seems like a dirty method bound to result in errors in any future browser update.
Is there any other way to figure out that the file provided is not in fact a file?