Mime Type Gibberish
Why is it that there are so many mime types for the same file extension? How is one supposed to determine the mime type of a file solely based on the extension, if for example there are multiple mime types associated with this extension?
Example:
.mp3 audio/mpeg3
.mp3 audio/x-mpeg-3
.mp3 video/mpeg
.mp3 video/x-mpeg
How is one supposed to know the default mime type? What does the x-
denote? Is this a linux/unix flavor for the mime type? And why is it that none of these are standardized (yet)?
Source taken from: Sitepoint However there are multiple other listings that produce similar spaghetti as well.
Edit:
I have a requirement that the an ASP.NET page should provide links to a few files in a source directory outside IIS. in Windows Server. I do not know what the files are, however i do know that I cannot provide full path to the file as it can be a security issue.
I am using code similar to this:
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
Response.TransmitFile( '[path to file]' );
Response.End();
where I substitute the ContentType property for the mime type of the actual file.
If you're using Framework 4.5 you can get the mimemapping using:
var mapping = System.Web.MimeMapping.GetMimeMapping("something.jpg");
If you're using Framework 4 you can access a non-public method to do the same like so:
var assembly = Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
var assemblyType = assembly.GetType("System.Web.MimeMapping");
var getMimeMappingMethod = assemblyType.GetMethod("GetMimeMapping", BindingFlags.Static | BindingFlags.NonPublic) ??
assemblyType.GetMethod("GetMimeMapping", BindingFlags.Static | BindingFlags.Public);
var mapping = (string)getMimeMappingMethod.Invoke(null, new object[] { fileName });
链接地址: http://www.djcxy.com/p/46932.html
上一篇: ASP.net。 浏览器未检测到下载文件的MIME类型
下一篇: Mime类型的垃圾