文件 API 的 .size 使用什么单位

What unit does the File API use for .size

我想了好一阵子了,但我不知道该如何测试。如果我允许用​​户上传文件(或者更确切地说“select 来自他们系统的文件)并且我希望文件不大于 X 大小,我会这样做:

    var file = $("#xml-upload-button")[0].files[0],
        fsize = file.size;

    if (fsize < 20000) {
        var reader = new FileReader();
        reader.readAsText(file);
        reader.onloadend = function() {
            if (reader.result) {
                // Something
            }
            else {
                // Something
            }
        };
    } else {
        return;
    }

这行得通,这不是问题所在。我只是想知道文件 API 使用什么单位来表示我的 fsize 值。位,还是字节?区别是至关重要的。我会告诉用户他们可以上传最大 2.5kB 或 20kB 的文件吗?

终于找到答案了,the docs说:

size

The size of the file in bytes as a read-only 64-bit integer.