不要在接受属性的值需要一台电脑知道MIME类型? [英] Do the values in the accept attribute require a computer to know the mime types?

查看:113
本文介绍了不要在接受属性的值需要一台电脑知道MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个标准的<输入类型=文件接受=.../> 其中的接受,是不同的MIME大名单类型。的我已经确认在服务器后端的文件类型的,但我要确保我不是在客户端上的用户界面筛选出有效文件。我知道旧的浏览器不会在所有的文件进行过滤,这是好的。我担心的是一个现代的浏览器可能无法识别的MIME类型,并筛选出实际上是有效的文件。

所以我的问题基本上是,如何可靠是'接受'属性?例如将一个浏览器识别的.docx MIME类型,如果没有安装Microsoft Office?此外,一些文件类型有与之相关的许多不同的可能MIME类型,它的问题,如果我只列出的MIME类型之一?

我不明白为什么规范最初使用MIME类型,这将是显著简单,如果他们刚刚使用摆在首位的扩展(如铬接受)我猜测更可靠。

有关我目前用默剧的完整列表:

 应用程序/ msword,
应用程序/ vnd.openxmlformats-officedocument.wordpro​​cessingml.document,
应用程序/ RTF,
应用程序/ msexcel的,
应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.sheet,
应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.template,
应用程序/ vnd.ms-excel.template.macroEnabled.12,
应用程序/ vnd.ms-excel.sheet.macroEnabled.12,
文/ CSV,
应用程序/ mspowerpoint,
应用程序/ vnd.openxmlformats-officedocument。presentationml。presentation,
应用程序/ vnd.ms - PowerPoint文件。presentation.macroEnabled.12,
应用程序/ vnd.ms - PowerPoint中,
应用程序/ vnd.openxmlformats-officedocument。presentationml.template,
应用程序/ vnd.openxmlformats-officedocument。presentationml.slideshow,
应用程序/ PDF,
图片/ JPG,
图像/ JPEG,
图像/ PNG,
图像/ BMP,
图像/ GIF,
text / plain的,
消息/ RFC822,
应用程序/ vnd.oasis.opendocument.text,
应用程序/ vnd.oasis.opendocument.s preadsheet,
应用程序/ vnd.oasis.opendocument。presentation,
应用程序/ Visio中,应用/ vnd.visio,
应用程序/ VST,
应用程序/ vnd.visio.webdrawing,
应用程序/ x-mspublisher


解决方案

规范允许您使用扩展以及MIME类型

在事实上,它实际上是建议您使用的两个的MIME类型和扩展。

至于要求的操作系统的识别的MIME类型,并没有真正意义,因为MIME类型是互联网协议文件标识符。它实际上取决于为MIME类型的用户代理(浏览器)的支持。由于这是一个相当新的结构,我也​​不会感到惊讶,如果浏览器只是最低限度由具有MIME类型和扩展名之间的共同映射支持吧。我无法想象,浏览器尝试与stat所有可读的文件,以确定MIME类型(这在我的经验甚至没有接近可靠反正)。 接受的意图似乎更有关更改文件如何上传对话框的外观,我怀疑任何浏览器确实是没有,但我可以肯定是错误的考虑浏览器如何快速释放都是时下。

如果你还在担心,你可以在常见的浏览器测试自己,因为它真的好像应该是每个用户代理,而不是每个OS。

so I have a standard <input type="file" accept="..."/> where the accept, is a large list of different mime types. I already verify the filetypes on the server backend but I want to be sure I am not filtering out valid files on the clients UI. I realise older browsers will not filter files at all, this is fine. My concern is that a modern browser may not recognise a mime-type and filter out files that are actually valid.

So my question is basically, how reliable is the 'accept' attribute? For example will a browser recognise the .docx mime type if microsoft office is not installed? Also, some file types have many different possible mime-types associated with them, does it matter if I only list one of the mime-types?

I don't understand why the specification originally used mime-types, it would be significantly simpler and I am guessing more reliable if they have had just used extensions in the first place (like chrome accepts).

For the complete list of mimes I am currently using:

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

解决方案

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

In fact, it actually recommends that you use both mime-type and extension.

As for requiring the OS to recognize the mime-type, that doesn't really make sense since mime-types are Internet protocol file identifiers. It actually depends on the user agent (browser) support for the mime-type. Since this is a fairly new construct, I wouldn't be surprised if browsers only minimally "support" it by having a common mapping between mime types and extensions. I can't imagine that the browser attempts to stat all readable files to determine mime type (which in my experience is not even close to dependable anyway). accept's intent seems to be more about changing how the file upload dialog looks, and I doubt any browser does that yet, although I could definitely be wrong considering how quick browser releases are nowadays.

If you're still concerned, you could test yourself in common browsers since it really seems like it should be per user agent rather than per OS.

这篇关于不要在接受属性的值需要一台电脑知道MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆