vsd是什么文件格式(如何打开vsd文件)
首发

vsd是什么文件格式(如何打开vsd文件)

优质
请用语音读文章

Mime Type(Content-Type)

MIME Type介绍 Content-Type 各种定义

多用途互联网邮件扩展(MIME。Multipurpose Internet Mail Extensions)是一个互联网标准。它扩展了电子邮件标准。使其能够支持非ASCII字符、二进制格式附件等多种格式的邮件消息。在万维网中使用的HTTP协议中也使用了MIME的框架。标准被扩展为互联网媒体类型。通常来说。浏览器通过MIME Type区分不同的媒体资源。目前版本:1.0。

MIME Type是经由IETF组织协商。以RFC形式作为建议标准发布在网上。通常只有一些在互联网上获得广泛应用的格式才会获得一个 MIME Type。如果是某个客户端自己定义的格式。一般只能以application/x- 开头。处理本地的文件。在没有人告诉浏览器某个文件的MIME Type的情况下。浏览器也会做一些默认的处理。这可能和在操作系统中给文件配置的MIME Type有关。

在HTTP中。MIME Type类型被定义在Content-Type header中。每个MIME类型由3部分组成:Content-Type: [type]/[subtype]。前者是数据大类别。后者定义具体的种类。

通过文件扩展名获取ContentType

importlombok.Getter;
importorg.apache.commons.lang3.StringUtils;

/**
*通过文件扩展名获取ContentType
*/
@Getter
publicenumMimeTypeEnum{

AAC("acc","AAC音频","audio/aac"),
ABW("abw","AbiWord文件","application/x-abiword"),
ARC("arc","存档文件","application/x-freearc"),
AVI("avi","音频视频交错格式","video/x-msvideo"),
AZW("azw","亚马逊Kindle电子书格式","application/vnd.amazon.ebook"),
BIN("bin","任何类型的二进制数据","application/octet-stream"),
BMP("bmp","WindowsOS/2位图图形","image/bmp"),
BZ("bz","BZip存档","application/x-bzip"),
BZ2("bz2","BZip2存档","application/x-bzip2"),
CSH("csh","C-Shell脚本","application/x-csh"),
css("css","级联样式表(CSS)","text/css"),
CSV("csv","逗号分隔值(CSV)","text/csv"),
DOC("doc","微软Word文件","application/msword"),
DOCX("docx","MicrosoftWord(OpenXML)","application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
EOT("eot","MSEmbeddedOpenType字体","application/vnd.ms-fontobject"),
EPUB("epub","电子出版物(EPUB)","application/epub+zip"),
GZ("gz","GZip压缩档案","application/gzip"),
GIF("gif","图形交换格式(GIF)","image/gif"),
HTM("htm","超文本标记语言(html)","text/html"),
HTML("html","超文本标记语言(HTML)","text/html"),
ICO("ico","图标格式","image/vnd.microsoft.icon"),
ICS("ics","iCalendar格式","text/calendar"),
JAR("jar","java存档","application/java-archive"),
JPEG("jpeg","JPEG图像","image/jpeg"),
JPG("jpg","JPEG图像","image/jpeg"),
js("js","JavaScript","text/javascript"),
JSON("json","JSON格式","application/json"),
JSONLD("jsonld","JSON-LD格式","application/ld+json"),
MID("mid","乐器数字接口(MIDI)","audio/midi"),
MIDI("midi","乐器数字接口(MIDI)","audio/midi"),
MJS("mjs","JavaScript模块","text/javascript"),
MP3("mp3","MP3音频","audio/mpeg"),
MPEG("mpeg","MPEG视频","video/mpeg"),
MPKG("mpkg","苹果安装程序包","application/vnd.apple.installer+xml"),
ODP("odp","OpenDocument演示文稿文档","application/vnd.oasis.opendocument.presentation"),
ODS("ods","OpenDocument电子表格文档","application/vnd.oasis.opendocument.spreadsheet"),
ODT("odt","OpenDocument文字文件","application/vnd.oasis.opendocument.text"),
OGA("oga","OGG音讯","audio/ogg"),
OGV("ogv","OGG视频","video/ogg"),
OGX("ogx","OGG","application/ogg"),
OPUS("opus","OPUS音频","audio/opus"),
OTF("otf","otf字体","font/otf"),
PNG("png","便携式网络图形","image/png"),
PDF("pdf","Adobe可移植文档格式(PDF)","application/pdf"),
PHP("php","php","application/x-httpd-php"),
PPT("ppt","MicrosoftPowerPoint","application/vnd.ms-powerpoint"),
PPTX("pptx","MicrosoftPowerPoint(OpenXML)","application/vnd.openxmlformats-officedocument.presentationml.presentation"),
RAR("rar","RAR档案","application/vnd.rar"),
RTF("rtf","富文本格式","application/rtf"),
SH("sh","BourneShell脚本","application/x-sh"),
SVG("svg","可缩放矢量图形(SVG)","image/svg+xml"),
SWF("swf","小型Web格式(SWF)或AdobeFlash文档","application/x-shockwave-flash"),
TAR("tar","磁带存档(TAR)","application/x-tar"),
TIF("tif","标记图像文件格式(TIFF)","image/tiff"),
TIFF("tiff","标记图像文件格式(TIFF)","image/tiff"),
TS("ts","MPEG传输流","video/mp2t"),
TTF("ttf","ttf字体","font/ttf"),
TXT("txt","文本(通常为ASCII或ISO8859-n","text/plain"),
VSD("vsd","微软Visio","application/vnd.visio"),
WAV("wav","波形音频格式","audio/wav"),
WEBA("weba","WEBM音频","audio/webm"),
WEBM("webm","WEBM视频","video/webm"),
WEBP("webp","WEBP图像","image/webp"),
WOFF("woff","Web开放字体格式(WOFF)","font/woff"),
WOFF2("woff2","Web开放字体格式(WOFF)","font/woff2"),
XHTML("xhtml","XHTML","application/xhtml+xml"),
XLS("xls","微软excel","application/vnd.ms-excel"),
XLSX("xlsx","微软Excel(OpenXML)","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
XML("xml","XML","application/xml"),
XUL("xul","XUL","application/vnd.mozilla.xul+xml"),
ZIP("zip","ZIP","application/zip"),
MIME_3GP("3gp","3GPPaudio/videocontainer","video/3gpp"),
MIME_3GP_WITHOUT_VIDEO("3gp","3GPPaudio/videocontainerdoesn'tcontainvideo","audio/3gpp2"),
MIME_3G2("3g2","3GPP2audio/videocontainer","video/3gpp2"),
MIME_3G2_WITHOUT_VIDEO("3g2","3GPP2audio/videocontainerdoesn'tcontainvideo","audio/3gpp2"),
MIME_7Z("7z","7-zip存档","application/x-7z-compressed");

//扩展名
privatefinalStringextension;
//说明
privatefinalStringexplain;
//contentType/mime类型
privatefinalStringmimeType;

/**
*@paramextension上传的文件扩展名
*@paramexplain类型说明
*@parammimeTypeMime对应的类型
*/
MimeTypeEnum(Stringextension,Stringexplain,StringmimeType){
this.extension=extension;
this.explain=explain;
this.mimeType=mimeType;
}

/**
*通过扩展名获取枚举类型
*
*@paramextension扩展名
*@return枚举类
*/
publicstaticMimeTypeEnumgetByExtension(Stringextension){
if(StringUtils.isEmpty(extension)){
returnnull;
}
for(MimeTypeEnumtypesEnum:MimeTypeEnum.values()){
if(extension.equals(typesEnum.getExtension())){
returntypesEnum;
}
}
returnnull;
}

/**
*Content-Type常用对照
*根据后缀获取Mime
*
*@paramfileType扩展名
*@returnmime类型
*/
publicstaticStringgetContentType(StringfileType){
MimeTypeEnummimeTypeEnum=MimeTypeEnum.getByExtension(fileType);
if(mimeTypeEnum!=null){
returnmimeTypeEnum.getMimeType();
}
return"application/octet-stream";
}

}

根据文件获取MimeType的几种方式

<!--hutool-all-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.6.5</version>
</dependency>
<!--commons.lang3-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.79</version>
</dependency>
<dependency>
<groupId>net.sf.jmimemagic</groupId>
<artifactId>jmimemagic</artifactId>
<version>0.1.4</version>
</dependency>

importcn.hutool.core.io.FileUtil;
importnet.sf.jmimemagic.*;

importjavax.activation.MimetypesFileTypeMap;
importjava.io.File;
importjava.io.IOException;
importjava.net.FileNameMap;
importjava.net.URLConnection;
importjava.nio.file.Files;

publicclassMimeTypeDemo{

publicstaticvoidmain(String[]args){
Filefile=FileUtil.file("d:/001.jpg");
//第一种方式
StringmimeType1="";
try{
Magicparser=newMagic();
MagicMatchmatch=parser.getMagicMatch(file,false);
mimeType1=match.getMimeType();
}catch(MagicParseExceptione){
e.printStackTrace();
}catch(MagicMatchNotFoundExceptione){
e.printStackTrace();
}catch(MagicExceptione){
e.printStackTrace();
}
System.out.println("第一种方式:"+mimeType1);
//第二种方式
StringmimeType2=newMimetypesFileTypeMap().getContentType(file);
System.out.println("第二种方式:"+mimeType2);
//第三种方式
StringmimeType3="";
try{
mimeType3=Files.probeContentType(file.toPath());
}catch(IOExceptione){
e.printStackTrace();
}
System.out.println("第三种方式:"+mimeType3);
//第四种方式
FileNameMapfileNameMap=URLConnection.getFileNameMap();
StringmimeType4=fileNameMap.getContentTypeFor(file.getParent());
System.out.println("第四种方式:"+mimeType4);

//通过文件扩展名获取ContentType
MimeTypeEnummimeTypeEnum=MimeTypeEnum.getByExtension("jpg");
System.out.println(mimeTypeEnum.getExplain()+","+mimeTypeEnum.getMimeType()+","+mimeTypeEnum.getExtension());
}

}

以上就是由优质生活领域创作者 生活常识网 整理编辑的,如果觉得有帮助欢迎收藏转发~

分享到 :
相关推荐

新百伦和new(斯特林上脚New)

请用语音读文章能分辨这两个标志是哪个品牌的吗?左边是美利坚健身鞋品牌NewBal[&...

我的世界盖房子教程有哪些(Minecraft我的世界)

请用语音读文章在我的世界中。总有些大神能够建造出神乎其神的神作。及其雄伟!有些建筑[...

有没有类似第五人格的游戏(这次能复制第五人格的成功吗)

请用语音读文章执笔。一位在游戏圈摸爬滚打十余年的在职老兵。天天聊游戏。关注不迷路哟[...

福州酒吧(酒吧餐馆管控收紧)

请用语音读文章夜幕降临之后总是不甘心让一天就这样平淡地结束听说白马河畔夜色撩人[&h...

发表评论

您的电子邮箱地址不会被公开。