How to distinguish folders and files drag and drop Ajax upload in FireFox

♀尐吖头ヾ 提交于 2020-01-03 02:25:10

问题


I can not find the way to distinguish between folders and files drop in FireFox Ajax. Looks like there are no signs in FireFox FileAPI that can tell if this is a folder or a file.

However I see that Google docs somehow can distinguish between folders and files drop. It does not relie on extensions or file length, files without extensions are uploaded correctly, as well as 0-lenth files are uploaded with no problem.

How do I distinguish between files and folders during D&D in FF?


回答1:


This blog post suggests trying to read the file and reacting to the exception that will be thrown if it is a folder.

if (!f.type && f.size%4096 == 0 && f.size <= 102400) {
    try {
        reader = new FileReader();
        reader.readAsBinaryString(f);
    } catch (NS_ERROR_FILE_ACCESS_DENIED) {
    //file is a directory
    }
}

In general: First assume the folder is a file and treat it like one, at some point things will go wrong and you can react to that.



来源:https://stackoverflow.com/questions/20378708/how-to-distinguish-folders-and-files-drag-and-drop-ajax-upload-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!