[英]Is there a way to get an extension for a given content type?
Is there a way to do the inverse of this? 有没有办法做到这一点?
content type by extension 内容类型扩展名
I have a WebResponse
which has a content type and I need to cache the response with the appropriate extension. 我有一个
WebResponse
,它有一个内容类型,我需要缓存响应与适当的扩展名。
image/png => .png image / png => .png
image/jpg => .jpg image / jpg => .jpg
Windows has a MIME-type database in the Registry. Windows在Registry中有一个MIME类型的数据库。 Internet Explorer uses this database to select the default extension for downloads in its
Save As
dialog. Internet Explorer使用此数据库在其“
Save As
对话框中选择下载的默认扩展名。
The machine-level database is under HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\MIME\\Database
, with user-specific overrides under HKEY_CURRENT_USER\\Software\\Classes\\MIME\\DataBase
. 机器级数据库位于
HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\MIME\\Database
,在HKEY_CURRENT_USER\\Software\\Classes\\MIME\\DataBase
下具有特定于用户的覆盖。 Windows merges these trees and exposes the result under HKEY_CLASSES_ROOT\\MIME\\DataBase
. Windows合并这些树并在
HKEY_CLASSES_ROOT\\MIME\\DataBase
下公开结果。
The Content-Type mappings are in a tree located under the Content Type
subkey; Content-Type映射位于
Content Type
子项下的树中; for example, the audio/mp3
type is located at: 例如,
audio/mp3
类型位于:
HKEY_CLASSES_ROOT\MIME\Database\Content Type\audio/mp3
The default file extension, including the leading period character, is in the Extension
named value. 默认文件扩展名(包括前导句点字符)位于
Extension
命名值中。
Since another answer on StackOverflow already contains a snippet to do this I won't reinvent the wheel here :-) 由于StackOverflow上的另一个答案已经包含了一个代码片段,我不会在这里重新发明轮子:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.