2013-02-21 63 views
0

所以我有一个标准的<input type="file" accept="..."/>其中accept,是不同MIME类型的大列表。 我已经验证了服务器后端上的文件类型,但我想确定我没有筛选出客户端UI上的有效文件。我意识到旧版浏览器根本不会过滤文件,这很好。我担心现代浏览器可能无法识别MIME类型并过滤出实际有效的文件。接受属性中的值是否需要计算机知道MIME类型?

所以我的问题基本上是'accept'属性有多可靠?例如,如果未安装Microsoft Office,浏览器是否会识别.docx mime类型?此外,某些文件类型有许多不同的可能的MIME类型与它们相关联,如果我只列出其中一种MIME类型,它是否重要?

我不明白为什么规范最初使用MIME类型,它会明显更简单,我猜如果他们有第一次使用扩展(如铬接受)更可靠。

对于我目前用默剧的完整列表:

application/msword, 
application/vnd.openxmlformats-officedocument.wordprocessingml.document, 
application/rtf, 
application/msexcel, 
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, 
application/vnd.openxmlformats-officedocument.spreadsheetml.template, 
application/vnd.ms-excel.template.macroEnabled.12, 
application/vnd.ms-excel.sheet.macroEnabled.12, 
text/csv, 
application/mspowerpoint, 
application/vnd.openxmlformats-officedocument.presentationml.presentation, 
application/vnd.ms-powerpoint.presentation.macroEnabled.12, 
application/vnd.ms-powerpoint, 
application/vnd.openxmlformats-officedocument.presentationml.template, 
application/vnd.openxmlformats-officedocument.presentationml.slideshow, 
application/pdf, 
image/jpg, 
image/jpeg, 
image/png, 
image/bmp, 
image/gif, 
text/plain, 
message/rfc822, 
application/vnd.oasis.opendocument.text, 
application/vnd.oasis.opendocument.spreadsheet, 
application/vnd.oasis.opendocument.presentation, 
application/visio,application/vnd.visio, 
application/vst, 
application/vnd.visio.webdrawing, 
application/x-mspublisher 

回答

1

The specification allows you to use extensions as well as mime types

事实上,它实际上建议您使用 MIME类型和扩展。

至于要求OS识别MIME类型,这是没有意义的,因为MIME类型是Internet协议文件标识符。它实际上取决于用户代理(浏览器)对mime类型的支持。由于这是一个相当新的构造,如果浏览器只通过MIME类型和扩展之间的通用映射来最小化地“支持”它,我不会感到惊讶。我无法想象浏览器试图统计所有可读文件来确定MIME类型(根据我的经验,它甚至不能接近可靠)。 accept的意图似乎更多地是关于如何改变文件上传对话框的外观,我怀疑任何浏览器都没有这样做,尽管我认为考虑当今的浏览器发布的速度如何是错误的。

如果您仍然担心,您可以在常见的浏览器中测试自己,因为它看起来应该是每个用户代理而不是每个操作系统。

相关问题