0

我有以下内容:

HTML

<input id="files" name="files" type="file" multiple="multiple" />
<button id='subButton' type='submit'>Upload (0) files</button>

Javascript

$("#files").change(function(evt) {
    debugger;
    $("#subButton").text("Upload (" + evt.target.files.length + ") files");
});

你可以在这个 Fiddle中看到它的作用。如果我选择 1,700 个文件,则代码可以正常工作,并且 evt.target.files.length 返回正确的文件数。但是,如果我选择目录中的所有文件(2279 - 总大小为 210MB),则 evt.target.files.length 返回 0。

File API 是否存在某种模棱两可的文件限制?

在我的 web.config 我有: maxRequestLength="700000" 它应该处理给定的文件大小。但是,这对我来说似乎是客户端而不是服务器端问题,因为没有任何内容提交给服务器。

有任何想法吗?

4

1 回答 1

1

This is not a limit of the HTML5 File API but of the browser implementation or operating system.

Testing Firefox on Windows Vista, for example, there seemed to be effectively no limit to the number of files I could select (I tested up to 10,000). On Chrome, it appeared to return 3758 of the selected files.

The difference is that Firefox is using the new IFileOpenDialog interface which returns the selected files as an enumeration, but Chrome seems to be using the old GetOpenFileName API, which relies on a fixed size buffer. If the buffer isn't big enough, it's supposed to return an error, but on Vista it just returns truncated and slightly corrupted data.

Interestingly, from the number of files returned by Chrome, and the knowledge of the filenames I was testing with, I can make a fairly good guess that the buffer size being used is probably 32768.

I'm guessing you're using Windows 7 or 8 and the GetOpenFileName API has been fixed to the extent that it now returns an error if you exceed the buffer size. So when you select too many files, the browser doesn't attempt to process the truncated data, and just returns 0.

The exact limit will be based on the length of the filenames and the path of the directory containing those files.

Other operating systems will obviously not have these same limits, but could have their own problems depending on the design of their file selection APIs.

于 2013-07-02T10:22:02.120 回答