i'm not sure if this issue was already opened, I did a search before post it, but would be useful any way of add a attribute to limit the size of files being added to input file. like:
<input type="file" max-size="2000" multiple required>
max size is the size in kbytes.
then after the user submit the form, html shows the validation message.
it could even be improved adding too: max-files attribute, that would limit how many files the user can add to the field
What would be interesting to know is how many developers encounter this problem (e.g., questions asked on Stack Overflow) and if there are popular libraries that provide workarounds (should be fairly easy to prototype with input.files[0].size et al).
What would be interesting to know is how many developers encounter this problem (e.g., questions asked on Stack Overflow)
(should be fairly easy to prototype with
input.files[0].sizeet al).
The question with 232 upvotes has an answer at https://stackoverflow.com/a/3717847/441757 with 302 upvotes that uses input.files[0].size.
if there are popular libraries that provide workarounds
That question with 232 upvotes also has an answer with 110 upvotes which provides a solution that relies on jQuery. The most-upvoted answers to the other two questions listed above also have solutions that rely on jQuery.
@smaug---- @tkent-google @rniwa thoughts on this? I guess in particular for "maximum size of all selected files" per the above data.
It would be a bit weird to have validation message if user selects too large file.
I wonder if it is possible to pass max size to OS level file pickers and then users couldn't even select too large files. (didn't immediately see anything on gtk's filepicker)
It would be a bit weird to have validation message if user selects too large file.
I wonder if it is possible to pass max size to OS level file pickers and then users couldn't even select too large files. (didn't immediately see anything on gtk's filepicker)
For macOS, I can't recall ever having seen any behavior in the filepicker that prevents me from picking particular files based on size. Same for Android.
Regardless, at the spec level, I wouldn't think we could assume the user is on a device/platform/OS with a filepicker that can limit selection to files below a certain size.
The validation message can be the fallback (and either we wouldn't expose the File object). If developers are otherwise writing their own validation message ours wouldn't be less weird and over time it could be improved by better file pickers.
few ideas:
use existing min/max attribute for controlling how many files you can pick
type="file" multiple min="2" max="2" require a front & back side for a double printed _something_type="file" multiple max="5" don't allow more then 5 image for a slideshow allow controlling byte size
type="file" multiple max-file-size="1024"type="file" multiple total-max-size="1024"maybe it also would be useful do ignore junk files by disallow empty/small files so a min size would be useful as well?
Any progress? I think changing spec to allow maxlength for and using bytes for the length would be the best way forward.
The only detail that needs to be decided is maxlength combined with multiple. I think the maxlength should be total bytes combined instead of per file selected. If both cases need to be handled, then having something like maxfilesize (bytes) and maxsubmissionsize (bytes) would be a better option.
I wonder if @hober @cdumez @mfreed7 @whatwg/forms have thoughts here?
Most helpful comment
few ideas:
use existing min/max attribute for controlling how many files you can pick
type="file" multiple min="2" max="2"require a front & back side for a double printed _something_type="file" multiple max="5"don't allow more then 5 image for a slideshowallow controlling byte size
type="file" multiple max-file-size="1024"type="file" multiple total-max-size="1024"maybe it also would be useful do ignore junk files by disallow empty/small files so a
min sizewould be useful as well?