Why doesn't accept work in file upload controls?

A

Andrea Desole

I'm trying to implement a file upload to upload only xml files. I tried
accept="text/xml", but that doesn't seem to work, with both Firefox and
IE (which is the browser I am writing the application for). The only
information I found tells me that browsers usually disregard the accept
attribute, for a reason that I absolutely can't understand. Accept is
part of HTML, and there is no reason for me not to consider it. Also,
specifying what files to show in an open dialog looks to me a perfectly
normal thing to do.
Can anyone explain this strange behavior, and if there is a solution for
that?
Thanks

Andrea
 
J

Jukka K. Korpela

Andrea Desole said:
I'm trying to implement a file upload to upload only xml files.

You can't, in practice. See http://www.cs.tut.fi/~jkorpela/forms/file.html
for details.
I tried
accept="text/xml", but that doesn't seem to work,

Indeed. Besides, on the theoretical side, if it worked it would limit input
to files of media type text/xml, and that's not the only possible media
type for XML.
The only
information I found tells me that browsers usually disregard the accept
attribute,

Read "usually" as "always".
for a reason that I absolutely can't understand.

Neither can I, but file input has in general been implemented in an awful
way. Now that the original specification of file input has become obsolete
and nothing better has been souped up, browser vendors have a good excuse
for not improving the situation. Besides, there's always XForms in the
horizon, and it will remove all the current problems with forms.
(Horizon = an imaginary horizontal line that draws away as you try to
approach it.)
Also,
specifying what files to show in an open dialog looks to me a perfectly
normal thing to do.

Well, in a sense, but most file systems actually have no media type concept
in the sense that would be relevant here. There's nothing in the file
system that tells which files are XML files, for example. Using the
filename suffix as an indicator is a very coarse trick and works, at best,
for a limited set of media types - inconsistently, since there is no
specification of the correspondence.
 
A

Andrea Desole

Jukka said:
You can't, in practice. See http://www.cs.tut.fi/~jkorpela/forms/file.html
for details.

yes, this is one of the pages I found on Google
Indeed. Besides, on the theoretical side, if it worked it would limit input
to files of media type text/xml, and that's not the only possible media
type for XML.

fair enough. But I could put more types together
Neither can I, but file input has in general been implemented in an awful
way. Now that the original specification of file input has become obsolete
and nothing better has been souped up, browser vendors have a good excuse
for not improving the situation. Besides, there's always XForms in the
horizon, and it will remove all the current problems with forms.
(Horizon = an imaginary horizontal line that draws away as you try to
approach it.)

That sounds promising :)
Oh well, I guess I can live without filter in the file upload.
Thanks for the information
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top