使用.NET,你怎么能找到基于文件签名没有扩展名的文件的MIME类型 [英] Using .NET, how can you find the mime type of a file based on the file signature not the extension

查看:168
本文介绍了使用.NET,你怎么能找到基于文件签名没有扩展名的文件的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个简单的方法来获得一个MIME类型,其中文件扩展名是不正确或不给,类似的这个问题只在.NET。

I am looking for a simple way to get a mime type where the file extension is incorrect or not given, something similar to this question only in .Net.

推荐答案

在Urlmon.dll中,有一个名为函数 FindMimeFromData

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

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

这篇关于使用.NET,你怎么能找到基于文件签名没有扩展名的文件的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆