如何区分文件夹和文件拖放在Firefox下降阿贾克斯上传拖放、文件夹、上传、文件

2023-09-10 18:08:46 作者:最毒老娘心

我无法找到文件夹和文件拖放在Firefox阿贾克斯区分的方式。貌似有在FireFox FileAPI没有迹象可以判断这是一个文件夹或文件。

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.

不过,我看到谷歌文档以某种方式可以文件夹和文件降之间区分。它不relie上扩展或文件长度,没有扩展的文件被正确加载,以及0-lenth文件上载没有问题。

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.

我如何在D&放区分文件和文件夹之间; d在FF

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

推荐答案

这的博客文章建议尝试读取文件和反应,如果它是一个文件夹,将抛出异常。

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.