A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

<input type=“file” maxlength=“1024” />

leaverou
2016-06-16

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:

chaals
2016-06-16

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?

leaverou
2016-06-16

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

chaals
2016-06-16

ah, yep.

Sorry for being dense, and thanks for explaining.

chaoaretasty
2016-06-16

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).

MT
2016-06-16

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.

leaverou
2016-06-16

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.

MT
2016-06-16

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.