mime type介绍 content-type 各种定义
多用途互联网邮件扩展(mime,multipurpo 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],前者是数据大类别,后者定义具体的种类。
import lombok.getter;import org.apache.commons.lang3.stringutils;/** * 通过文件扩展名获取contenttype */@getterpublic enum mimetypeenum { aac("acc", "aac音频", "audio/aac"), abw("abw", "abiword文件", "application/x-abiword"), arc("arc", "存档文件", "application/x-freea维护英文rc"), avi("avi", "音频视频交错格式", "video/x-msvideo"), azw("azw", "亚马逊k明史张溥传indle电子书格式", "application/vnd.amazon.ebook"), bin("bin", "任何类型的二进制数据", "application/octet-stream"), bmp("bmp", "windows os / 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文件", "appli作文标题大全优秀cation/msword"), docx("docx", "microsoft word(openxml)", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"), eot("eot", "ms embedded opentype字体", "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.prentation"), 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", "microsoft powerpoint", "application/vnd.ms-powerpoint"), pptx("pptx", "microsoft powerpoint(openxml)", "application/vnd.openxmlformats-officedocument.prentationml.prentation"), rar("rar", "rar档案", "application/vnd.rar"), rtf("rtf", "富文本格式", "application/rtf"), sh("sh", "bourne shell脚本", "application/x-sh"), svg("svg", "可缩放矢量图形(svg)", "image/svg+xml"), swf("swf", "小型web格式(swf)或adobe flash文档", "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或iso 8859- 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", "3gpp audio/video container", "video/3gpp"), mime_3gp_without_video("3gp", "3gpp audio/video container doesn't contain video", "audio/3gpp2"), mime_3g2("3g2", "3gpp2 audio/video container", "video/3gpp2"), mime_3g2_without_video("3g2", "3gpp2 audio/video container doesn't contain video", "audio/3gpp2"), mime_7z("7z", "7-zip存档", "application/x-7z-compresd"); //扩展名 private final string extension; //说明 private final string explain; //contenttype/mime类型 private final string mimetype; /** * @param extension 上传的文件扩展名 * @param explain 类型说明 * @param mimetype mime对应的类型 */ mimetypeenum(string extension, string explain, string mimetype) { this.extension = extension; this.explain = explain; this.mimetype = mimetype; } /** * 通过扩展名获取枚举类型 * * @param extension 扩展名 * @return 枚举类 */ public static mimetypeenum getbyextension(string extension) { if (stringutils.impty(extension)) { return null; } for (mimetypeenum typenum : mimetypeenum.values()) { if (extension.equals(typenum.getextension())) { return typenum; } } return null; } /** * content-type常用对照 * 根据后缀获取mime * * @param filetype 扩展名 * @return mime类型 */ public static string getcontenttype(string filetype) { mimetypeenum mimetypeenum = mimetypeenum.getbyextension(filetype); if (mimetypeenum != null) { return mimetypeenum.getmimetype(); } return "application/octet-stream"; }}
<!-- 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>
import cn.hutool.core.io.fileutil;import net.sf.jmimemagic.*;import javax.activation.mimetypesfiletype电子科学与技术是学什么的map;import java.io.file;import java.io.ioexception;import java.net.filenamemap;import java.net.urlconnection;import java.nio.file.files;public class mimetypedemo { public static void main(string[] args) { file file = fileutil.file("d:/001.jpg"); // 第一种方式 string mimetype1 = ""; try { magic parr = new magic(); magicmatch match = parr.getmagicmatch(file, fal); mimetype1 = match.getmimetype(); } catch (magicparexception e) { e.printstacktrace(); } catch (magicmatchnotfoundexception e) { e.printstacktrace(); } catch (magicexception e) { e.printstacktrace(); } system.out.println("第一种方式: " + mimetype1); // 第二种方式 string mimetype2 = new mimetypesfiletypemap().getcontenttype(file); system.out.println("第二种方式: " + mimetype2); // 第三种方式 string mimetype3 = ""; try { mimetype3 = files.probecontenttype(file.topath()); } catch (ioexception e) { e.printstacktrace(); } system.out.println("第三种方式: " + mimetype3); // 第四种方式 filenamemap filenamemap = urlconnection.getfilenamemap(); string mimetype4 = filenamemap.getcontenttypefor(file.getparent()); system.out.println("第四种方式: " + mimetype4); // 通过文件扩展名获取contenttype mimetypeenum mimetypeenum = mimetypeenum.getbyextension("jpg"); system.out.println(mimetypeenum.getexplain()+ " , "+mimetypeenum.getmimetype()+ " , "+mimetypeenum.getextension()); }}
本文发布于:2023-04-05 06:01:59,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/111834a30ef4056c832c43afd4ec156a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:vsd格式用什么文件(vsd文件编辑方式).doc
本文 PDF 下载地址:vsd格式用什么文件(vsd文件编辑方式).pdf
留言与评论(共有 0 条评论) |