I have a form which can have multiple file inputs (one file per input, not multi select).
When I submit the form, how do I get an array of all input[type="file"] contents and use FileReader to look at the file sizes before they are uploaded, and prevent it if any of the files is too large?
$('#MyForm').submit(function() {
});
I can’t figure this out at all from what limited FileReader documentation I can find. Or not get it to work, anyway…
The problem was the way in which I was trying to select the files from the file input with jQuery. Here are some example solutions:
If you have one file input, and the user can only select a single file:
If you have one file input, with multiple file select:
If you have multiple file inputs, with multiple file select:
Once you have the File object, here are the properties you have access to (apart from size):
https://developer.mozilla.org/en-US/docs/DOM/File#Properties