且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用.NET,你怎么能找到基于文件签名没有扩展名的文件的MIME类型

更新时间:2022-11-27 12:10:30

在Urlmon.dll中,有一个名为函数 FindMimeFromData ​​ code>。

In Urlmon.dll, there's a function called FindMimeFromData.

从文档

MIME类型检测,或数据嗅探,是指确定来自二进制数据的适当的MIME类型的过程。最终结果取决于服务器提供的MIME类型标头,文件扩展名,和/或数据本身的组合。一般,只有第一256字节的数据是显著。

MIME type detection, or "data sniffing," refers to the process of determining an appropriate MIME type from binary data. The final result depends on a combination of server-supplied MIME type headers, file extension, and/or the data itself. Usually, only the first 256 bytes of data are significant.

所以,从文件中读取的第一个(最多)256个字节,并把它传递给 FindMimeFromData ​​ code>。

So, read the first (up to) 256 bytes from the file and pass it to FindMimeFromData.