为什么 Urlmon.dll 中的 FindMimeFromData 函数返回 MIME 类型“application/octet-stream”?对于许多文件类型?
为什么 Urlmon.dll 中的 FindMimeFromData 函数对许多文件类型返回 MIME 类型“application/octet-stream”,而通过文件扩展名检查 MIME 类型(即针对 Windows 注册表)会返回更精确的类型?
例如,mp3 是“application/octet-stream”而不是“audio/mp3”。
基本上,我想验证扩展名不正确的上传文件。此方法似乎适用于许多图像文件、xml 等。
问题类似于 这个,但提供的解决方案不适合验证上传的文件,因为返回的 MIME 类型不同/不明确。
Why does the FindMimeFromData function from Urlmon.dll return MIME type “application/octet-stream” for many file types, whereas checking MIME type by file extension (I.e. against windows registry) returns a more precise type?
For example, mp3 is an “application/octet-stream” instead of “audio/mp3”.
Basically, I want to verify an uploaded file with incorrect extension. This method seems to work for many image files, xml, etc.
The question is similar to this one, but the provided solution is not suited for validating uploaded files, because of different/ambiguous MIME types returned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读 FindMimeFromData 的文档引导我到 Internet Explorer 中的 MIME 类型检测。根据该信息,硬编码查找 26不同的 MIME 类型,这在当今世界是相当小的。 “音频/mp3”不是其中之一。
不幸的是,看起来
FindMimeFromData
对于确定现代 MIME 类型并不是很有用。Reading the documentation for FindMimeFromData lead me to MIME Type Detection in Internet Explorer. According to that information it is hard-coded to find 26 different MIME types, which is quite small in today's world. "audio/mp3" is not one of them.
Unfortunately, it looks like
FindMimeFromData
won't be very useful for determining modern MIME types.这里有一个很好的解决方案: https://stackoverflow.com/a/9435701/74585 尝试确定文件类型如果 FindMimeFromData 返回“application/octet-stream”“text/plain”或根本不返回任何内容,则从注册表(通过文件扩展名?)。
这是一个 .NET 文件类型检测库 http://filetypeDetective.codeplex.com/ 但它只检测目前文件数量很少。
There's a nice solution here: https://stackoverflow.com/a/9435701/74585 which tries to determine the file type from the registry (by file extension?) if FindMimeFromData returns "application/octet-stream" "text/plain" or nothing at all.
Here's a .NET file type detecting library http://filetypedetective.codeplex.com/ but it only detects a smallish number of files at the moment.