Why does the FindMimeFromData function from Urlmon.dll return MIME type “application/octet-stream” for many file types?

前端 未结 2 1400
旧时难觅i
旧时难觅i 2021-01-11 19:07

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. ag

相关标签:
2条回答
  • 2021-01-11 19:52

    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.

    0 讨论(0)
  • 2021-01-11 20:10

    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 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).

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

    0 讨论(0)
提交回复
热议问题