为什么 Urlmon.dll 的 FindMimeFromData 函数会为许多文件类型返回 MIME 类型“application/octet-stream”,而通过文件扩展名(即针对 Windows 注册表)检查 MIME 类型会返回更精确的类型?
例如,mp3 是“application/octet-stream”而不是“audio/mp3”。
基本上,我想验证一个扩展名不正确的上传文件。这种方法似乎适用于许多图像文件、xml 等。
问题类似于this one ,但提供的解决方案不适合验证上传的文件,因为返回了不同/不明确的 MIME 类型。
最佳答案
阅读 FindMimeFromData 的文档带我到MIME Type Detection in Internet Explorer .根据该信息,可以通过硬编码找到 26 different MIME types。 ,这在当今世界是相当小的。 “音频/mp3”不是其中之一。
FindMimeFromData contains hard-coded tests for (currently 26) separate MIME type (see Known MIME Types). This means that if a given buffer contains data in the format of one of these MIME types, a test exists in FindMimeFromData that is designed (by scanning through the buffer contents) to recognize the corresponding MIME type. A MIME type is known if it is one of these N MIME types. A MIME type is ambiguous if it is "text/plain," "application/octet-stream," an empty string, or null (that is, the server failed to provide it).
不幸的是,看起来 FindMimeFromData
对于确定现代 MIME 类型不是很有用。
关于c# - 为什么 Urlmon.dll 的 FindMimeFromData 函数会为许多文件类型返回 MIME 类型 “application/octet-stream”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4833113/