为什么从Urlmon.dll的回报MIME类型“应用程序/八位字节流”对许多文件类型FindMimeFromData功能?字节、文件类型、应用程序、类型

2023-09-03 03:30:45 作者:浮世淸歡.

为什么从Urlmon.dll的回报MIME类型应用程序/八位字节流对许多文件类型FindMimeFromData功能,而按文件扩展名检查MIME类型(即对windows的注册表)返回更precise类型?

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?

例如,MP3是不是音频/ MP3的应用程序/八位字节流。

For example, mp3 is an "application/octet-stream" instead of "audio/mp3".

基本上,我想验证上传的文件不正确的扩展。这种方法似乎工作的许多图像文件,XML等。

Basically, I want to verify an uploaded file with incorrect extension. This method seems to work for many image files, xml, etc.

现在的问题是类似this 之一,但所提供的解决方案是不适合的,因为不同的验证上传的文件,/模棱两可的MIME类型返回。

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.

推荐答案

阅读文档的 FindMimeFromData 导致我 MIME类型检测在Internet Explorer 。根据这一信息,它是硬codeD找到 26个不同的MIME类型的,这是相当小的在今天的世界。 音频/ MP3是不是其中之一。

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.

FindMimeFromData的包含硬codeD测试(目前为26)单独的MIME类型(参见已知的MIME类型)。这意味着,如果一个给定的缓冲器中包含的数据在这些MIME类型中的一个的格式,在测试中FindMimeFromData被设计(通过扫描通过缓冲器的内容)的存在是为了确认相应的MIME类型。如果是这N个MIME类型中的一种MIME类型是已知的。 MIME类型是不明确的,如果它是text / plain的,应用程序/八位字节流,一个空字符串,或空(也就是服务器无法提供的话)。

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类型。

Unfortunately, it looks like FindMimeFromData won't be very useful for determining modern MIME types.