Reputation: 11197
I have the following:
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");
});
You can see it in action in this Fiddle. If I select 1,700 files, the code works fine and the correct number of files is returned by evt.target.files.length. However, if I select all the files in my directory (2279 -- total size of 210MB), then evt.target.files.length returns a 0.
Is there some sort of ambiguous file limit with the File API?
In my web.config I have: maxRequestLength="700000" which should handle the given size of the files. However, this seems to be a client rather than a server side issue to me in that nothing is being submitted to the server.
Any ideas?
Upvotes: 0
Views: 266
Reputation: 23001
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.
Upvotes: 1