<input type="file" maxlength="1024" />


#1

Basically syntactic sugar for <input type="file" onchange="this.setCustomValidity(this.files[0].size > this.maxlength? 'some error about file being too large' : '')"> (ofc for all files if multiple) The attribute is already there, we may as well do something with it :slight_smile:


#2

Just to check, you mean it would produce an error instead of picking the file if you chose a file that was more bytes than maxlength?


#3

No, it would allow picking the file and make the control invalid with all that that entails.


#4

ah, yep.

Sorry for being dense, and thanks for explaining.


#5

I like it but when using <input type="file" multiple length="1024" /> does length refer to total length or length per file? I can see good use cases for both and would almost want a way to specify both cases (eg an email client that limits to a maximum of 10meg of attachments and an image gallery that limits 2meg per image).


#6

While the idea itself may make sense (for example, PHP has a similar feature via a hidden form field with name="MAX_FILE_SIZE"), it would probably be somewhat confusing to reuse the existing maxlength attribute with a quite different meaning.

A potentially more reasonable option is to use a separate attribute with a more specific and clear name like maxfilesize.


#7

Reusing existing attributes is very much in the spirit of HTML, see multiple attribute on file inputs vs range inputs: You could argue the functionality is even more different there. Also, I don’t see how it’s that different. It’s setting the maximum length of the input, in both cases.


#8

Text length is typically measured in characters while file size is measured in bytes.

Let’s imagine a user uploads a UTF-8-encoded text file. Should maxlength be applied to the file size or to the number of characters in the file? While it’s somewhat obvious for us, in the context of this topic, that it’s about bytes, it may be confusing for authors in general.

A more clear and specific attribute name would rule out such ambiguity.