Why do the major browsers not support HTMLs ACCEPT attribute for input type="file"?
Asked Answered
A

4

5

Does anyone know how to use the accept attribute in input tags? I can see it documented, but w3schools indicates that it is not supported by any of the major browsers. Testing also confirms this.

I know that validation should be done server-side, and am doing that now. But it'd be nice to have it restrict the types of files in the file upload dialog for usability.

Edit: I am fully aware of the security implications of client-side only validation. I do not intend to remove server-side validation and am looking for a way to improve usability.

Afterbrain answered 16/11, 2009 at 18:28 Comment(3)
Even if it would be supported, that wouldn’t save you from validating the input on the server side.Vitalism
+1 for usability! Waiting 40 seconds for something to upload only to be told it's not good enough is not the greatest user experience.Soutane
Actually, most major browsers DO support the attribute inasmuch as they filter the file types shown in the file picker dialog. However, it's trivial to get around it by changing file extensions, so you still have to check server-side.Gilli
B
3

The reason why browsers don't actually implement the ACCEPT attribute is that MIME type validation is a science and not just as easy as reading a file extension. Even server-side MIME type verification can be difficult as noted by MediaWiki:

http://www.mediawiki.org/wiki/Manual:Mime_type_detection

Notice they attempt to verify the MIME type even server-side.

Blackface answered 16/11, 2009 at 18:42 Comment(0)
G
3

This attribute is supported by every major browser. Useful links are-- caniuse.com

w3 schools browser support for accept attriute

Thought it would be helpful for someone who wants to know about the browser support of HTML accept attribute.

Grope answered 19/1, 2017 at 4:19 Comment(0)
M
1

The most pedantic reason is that it's not required by the HTML4 specification (emphasis mine):

This attribute specifies a comma-separated list of content types that a server processing this form will handle correctly. User agents may use this information to filter out non-conforming files when prompting a user to select files to be sent to the server.

It's an optional feature.

I would personally love to see this. When given image/*, for example, the browser could bring up the user's photo library as the default location and use large icons. text/* could go to the documents folder, etc. Mobile browsers, such as the iPhone, which typically don't allow file uploads at all, could use this to bring up the gallery when the form is expecting an image. We could get crazy and connect to the scanner if desired. The possibilities are endless.

However, this feature is not in common use, and it could be terribly confusing for file upload dialogs to operate differently depending on what the web site supports.

Mach answered 16/11, 2009 at 18:52 Comment(0)
G
0

Supporting this tag would mean implementing a way for the browser to determine the MIME type of a local resource, and this would incur a fair amount of heuristics and possible exposure to code injection and/or other vulnerabilities, that browsers already have their fair share of.

Goodwin answered 16/11, 2009 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.