对接Minio等OSS文件存储的时候,我们市场会发现需要填写文件格式,不然默认就是application/octet-stream 这种二进制文件流,需要我们自己手动改文件拓展名才能打开
这里我通过脚本的方式写了一个枚举类,因为实在太多了,我一个个CV,估计天都亮了
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* HTTP Content-type对照表
*
* @author louis
* @since 2023-03-06
*/
public enum FileMimeEnums {
FILE_DEFAULT(".*", "application/octet-stream"),
FILE_001(".001", "application/x-001"),
FILE_301(".301", "application/x-301"),
FILE_323(".323", "text/h323"),
FILE_906(".906", "application/x-906"),
FILE_907(".907", "drawing/907"),
FILE_A11(".a11", "application/x-a11"),
FILE_ACP(".acp", "audio/x-mei-aac"),
FILE_AI(".ai", "application/postscript"),
FILE_AIF(".aif", "audio/aiff"),
FILE_AIFC(".aifc", "audio/aiff"),
FILE_AIFF(".aiff", "audio/aiff"),
FILE_ANV(".anv", "application/x-anv"),
FILE_ASA(".asa", "text/asa"),
FILE_ASF(".asf", "video/x-ms-asf"),
FILE_ASP(".asp", "text/asp"),
FILE_ASX(".asx", "video/x-ms-asf"),
FILE_AU(".au", "audio/basic"),
FILE_AVI(".avi", "video/avi"),
FILE_AWF(".awf", "application/vnd.adobe.workflow"),
FILE_BIZ(".biz", "text/xml"),
FILE_BMP(".bmp", "application/x-bmp"),
FILE_BOT(".bot", "application/x-bot"),
FILE_C4T(".c4t", "application/x-c4t"),
FILE_C90(".c90", "application/x-c90"),
FILE_CAL(".cal", "application/x-cals"),
FILE_CAT(".cat", "application/vnd.ms-pki.seccat"),
FILE_CDF(".cdf", "application/x-netcdf"),
FILE_CDR(".cdr", "application/x-cdr"),
FILE_CEL(".cel", "application/x-cel"),
FILE_CER(".cer", "application/x-x509-ca-cert"),
FILE_CG4(".cg4", "application/x-g4"),
FILE_CGM(".cgm", "application/x-cgm"),
FILE_CIT(".cit", "application/x-cit"),
FILE_CLASS(".class", "java/*"),
FILE_CML(".cml", "text/xml"),
FILE_CMP(".cmp", "application/x-cmp"),
FILE_CMX(".cmx", "application/x-cmx"),
FILE_COT(".cot", "application/x-cot"),
FILE_CRL(".crl", "application/pkix-crl"),
FILE_CRT(".crt", "application/x-x509-ca-cert"),
FILE_CSI(".csi", "application/x-csi"),
FILE_CSS(".css", "text/css"),
FILE_CUT(".cut", "application/x-cut"),
FILE_DBF(".dbf", "application/x-dbf"),
FILE_DBM(".dbm", "application/x-dbm"),
FILE_DBX(".dbx", "application/x-dbx"),
FILE_DCD(".dcd", "text/xml"),
FILE_DCX(".dcx", "application/x-dcx"),
FILE_DER(".der", "application/x-x509-ca-cert"),
FILE_DGN(".dgn", "application/x-dgn"),
FILE_DIB(".dib", "application/x-dib"),
FILE_DLL(".dll", "application/x-msdownload"),
FILE_DOC(".doc", "application/msword"),
FILE_DOT(".dot", "application/msword"),
FILE_DRW(".drw", "application/x-drw"),
FILE_DTD(".dtd", "text/xml"),
FILE_DWF(".dwf", "application/x-dwf"),
FILE_DWG(".dwg", "application/x-dwg"),
FILE_DXB(".dxb", "application/x-dxb"),
FILE_DXF(".dxf", "application/x-dxf"),
FILE_EDN(".edn", "application/vnd.adobe.edn"),
FILE_EMF(".emf", "application/x-emf"),
FILE_EML(".eml", "message/rfc822"),
FILE_ENT(".ent", "text/xml"),
FILE_EPI(".epi", "application/x-epi"),
FILE_EPS(".eps", "application/x-ps"),
FILE_ETD(".etd", "application/x-ebx"),
FILE_EXE(".exe", "application/x-msdownload"),
FILE_FAX(".fax", "image/fax"),
FILE_FDF(".fdf", "application/vnd.fdf"),
FILE_FIF(".fif", "application/fractals"),
FILE_FO(".fo", "text/xml"),
FILE_FRM(".frm", "application/x-frm"),
FILE_G4(".g4", "application/x-g4"),
FILE_GBR(".gbr", "application/x-gbr"),
FILE_GCD(".gcd", "application/x-gcd"),
FILE_GIF(".gif", "image/gif"),
FILE_GL2(".gl2", "application/x-gl2"),
FILE_GP4(".gp4", "application/x-gp4"),
FILE_HGL(".hgl", "application/x-hgl"),
FILE_HMR(".hmr", "application/x-hmr"),
FILE_HPG(".hpg", "application/x-hpgl"),
FILE_HPL(".hpl", "application/x-hpl"),
FILE_HQX(".hqx", "application/mac-binhex40"),
FILE_HRF(".hrf", "application/x-hrf"),
FILE_HTA(".hta", "application/hta"),
FILE_HTC(".htc", "text/x-component"),
FILE_HTM(".htm", "text/html"),
FILE_HTML(".html", "text/html"),
FILE_HTT(".htt", "text/webviewhtml"),
FILE_HTX(".htx", "text/html"),
FILE_ICB(".icb", "application/x-icb"),
FILE_ICO(".ico", "image/x-icon"),
FILE_IFF(".iff", "application/x-iff"),
FILE_IG4(".ig4", "application/x-g4"),
FILE_IGS(".igs", "application/x-igs"),
FILE_III(".iii", "application/x-iphone"),
FILE_IMG(".img", "application/x-img"),
FILE_INS(".ins", "application/x-internet-signup"),
FILE_ISP(".isp", "application/x-internet-signup"),
FILE_IVF(".IVF", "video/x-ivf"),
FILE_JAVA(".java", "java/*"),
FILE_JFIF(".jfif", "image/jpeg"),
FILE_JPE(".jpe", "image/jpeg"),
FILE_JPEG(".jpeg", "image/jpeg"),
FILE_JPG(".jpg", "image/jpeg"),
FILE_JS(".js", "application/x-javascript"),
FILE_JSP(".jsp", "text/html"),
FILE_LA1(".la1", "audio/x-liquid-file"),
FILE_LAR(".lar", "application/x-laplayer-reg"),
FILE_LATEX(".latex", "application/x-latex"),
FILE_LAVS(".lavs", "audio/x-liquid-secure"),
FILE_LBM(".lbm", "application/x-lbm"),
FILE_LMSFF(".lmsff", "audio/x-la-lms"),
FILE_LS(".ls", "application/x-javascript"),
FILE_LTR(".ltr", "application/x-ltr"),
FILE_M1V(".m1v", "video/x-mpeg"),
FILE_M2V(".m2v", "video/x-mpeg"),
FILE_M3U(".m3u", "audio/mpegurl"),
FILE_M4E(".m4e", "video/mpeg4"),
FILE_MAC(".mac", "application/x-mac"),
FILE_MAN(".man", "application/x-troff-man"),
FILE_MATH(".math", "text/xml"),
FILE_MDB(".mdb", "application/msaccess"),
FILE_MFP(".mfp", "application/x-shockwave-flash"),
FILE_MHT(".mht", "message/rfc822"),
FILE_MHTML(".mhtml", "message/rfc822"),
FILE_MI(".mi", "application/x-mi"),
FILE_MID(".mid", "audio/mid"),
FILE_MIDI(".midi", "audio/mid"),
FILE_MIL(".mil", "application/x-mil"),
FILE_MML(".mml", "text/xml"),
FILE_MND(".mnd", "audio/x-musicnet-download"),
FILE_MNS(".mns", "audio/x-musicnet-stream"),
FILE_MOCHA(".mocha", "application/x-javascript"),
FILE_MOVIE(".movie", "video/x-sgi-movie"),
FILE_MP1(".mp1", "audio/mp1"),
FILE_MP2(".mp2", "audio/mp2"),
FILE_MP2V(".mp2v", "video/mpeg"),
FILE_MP3(".mp3", "audio/mp3"),
FILE_MP4(".mp4", "video/mpeg4"),
FILE_MPA(".mpa", "video/x-mpg"),
FILE_MPD(".mpd", "application/vnd.ms-project"),
FILE_MPE(".mpe", "video/x-mpeg"),
FILE_MPEG(".mpeg", "video/mpg"),
FILE_MPG(".mpg", "video/mpg"),
FILE_MPGA(".mpga", "audio/rn-mpeg"),
FILE_MPP(".mpp", "application/vnd.ms-project"),
FILE_MPS(".mps", "video/x-mpeg"),
FILE_MPT(".mpt", "application/vnd.ms-project"),
FILE_MPV(".mpv", "video/mpg"),
FILE_MPV2(".mpv2", "video/mpeg"),
FILE_MPW(".mpw", "application/vnd.ms-project"),
FILE_MPX(".mpx", "application/vnd.ms-project"),
FILE_MTX(".mtx", "text/xml"),
FILE_MXP(".mxp", "application/x-mmxp"),
FILE_NET(".net", "image/pnetvue"),
FILE_NRF(".nrf", "application/x-nrf"),
FILE_NWS(".nws", "message/rfc822"),
FILE_ODC(".odc", "text/x-ms-odc"),
FILE_OUT(".out", "application/x-out"),
FILE_P10(".p10", "application/pkcs10"),
FILE_P12(".p12", "application/x-pkcs12"),
FILE_P7B(".p7b", "application/x-pkcs7-certificates"),
FILE_P7C(".p7c", "application/pkcs7-mime"),
FILE_P7M(".p7m", "application/pkcs7-mime"),
FILE_P7R(".p7r", "application/x-pkcs7-certreqresp"),
FILE_P7S(".p7s", "application/pkcs7-signature"),
FILE_PC5(".pc5", "application/x-pc5"),
FILE_PCI(".pci", "application/x-pci"),
FILE_PCL(".pcl", "application/x-pcl"),
FILE_PCX(".pcx", "application/x-pcx"),
FILE_PDF(".pdf", "application/pdf"),
FILE_PDX(".pdx", "application/vnd.adobe.pdx"),
FILE_PFX(".pfx", "application/x-pkcs12"),
FILE_PGL(".pgl", "application/x-pgl"),
FILE_PIC(".pic", "application/x-pic"),
FILE_PKO(".pko", "application/vnd.ms-pki.pko"),
FILE_PL(".pl", "application/x-perl"),
FILE_PLG(".plg", "text/html"),
FILE_PLS(".pls", "audio/scpls"),
FILE_PLT(".plt", "application/x-plt"),
FILE_PNG(".png", "image/png"),
FILE_POT(".pot", "application/vnd.ms-powerpoint"),
FILE_PPA(".ppa", "application/vnd.ms-powerpoint"),
FILE_PPM(".ppm", "application/x-ppm"),
FILE_PPS(".pps", "application/vnd.ms-powerpoint"),
FILE_PPT(".ppt", "application/vnd.ms-powerpoint"),
FILE_PR(".pr", "application/x-pr"),
FILE_PRF(".prf", "application/pics-rules"),
FILE_PRN(".prn", "application/x-prn"),
FILE_PRT(".prt", "application/x-prt"),
FILE_PS(".ps", "application/postscript"),
FILE_PTN(".ptn", "application/x-ptn"),
FILE_PWZ(".pwz", "application/vnd.ms-powerpoint"),
FILE_R3T(".r3t", "text/vnd.rn-realtext3d"),
FILE_RA(".ra", "audio/vnd.rn-realaudio"),
FILE_RAM(".ram", "audio/x-pn-realaudio"),
FILE_RAS(".ras", "application/x-ras"),
FILE_RAT(".rat", "application/rat-file"),
FILE_RDF(".rdf", "text/xml"),
FILE_REC(".rec", "application/vnd.rn-recording"),
FILE_RED(".red", "application/x-red"),
FILE_RGB(".rgb", "application/x-rgb"),
FILE_RJS(".rjs", "application/vnd.rn-realsystem-rjs"),
FILE_RJT(".rjt", "application/vnd.rn-realsystem-rjt"),
FILE_RLC(".rlc", "application/x-rlc"),
FILE_RLE(".rle", "application/x-rle"),
FILE_RM(".rm", "application/vnd.rn-realmedia"),
FILE_RMF(".rmf", "application/vnd.adobe.rmf"),
FILE_RMI(".rmi", "audio/mid"),
FILE_RMJ(".rmj", "application/vnd.rn-realsystem-rmj"),
FILE_RMM(".rmm", "audio/x-pn-realaudio"),
FILE_RMP(".rmp", "application/vnd.rn-rn_music_package"),
FILE_RMS(".rms", "application/vnd.rn-realmedia-secure"),
FILE_RMVB(".rmvb", "application/vnd.rn-realmedia-vbr"),
FILE_RMX(".rmx", "application/vnd.rn-realsystem-rmx"),
FILE_RNX(".rnx", "application/vnd.rn-realplayer"),
FILE_RP(".rp", "image/vnd.rn-realpix"),
FILE_RPM(".rpm", "audio/x-pn-realaudio-plugin"),
FILE_RSML(".rsml", "application/vnd.rn-rsml"),
FILE_RT(".rt", "text/vnd.rn-realtext"),
FILE_RTF(".rtf", "application/msword"),
FILE_RV(".rv", "video/vnd.rn-realvideo"),
FILE_SAM(".sam", "application/x-sam"),
FILE_SAT(".sat", "application/x-sat"),
FILE_SDP(".sdp", "application/sdp"),
FILE_SDW(".sdw", "application/x-sdw"),
FILE_SIT(".sit", "application/x-stuffit"),
FILE_SLB(".slb", "application/x-slb"),
FILE_SLD(".sld", "application/x-sld"),
FILE_SLK(".slk", "drawing/x-slk"),
FILE_SMI(".smi", "application/smil"),
FILE_SMIL(".smil", "application/smil"),
FILE_SMK(".smk", "application/x-smk"),
FILE_SND(".snd", "audio/basic"),
FILE_SOL(".sol", "text/plain"),
FILE_SOR(".sor", "text/plain"),
FILE_SPC(".spc", "application/x-pkcs7-certificates"),
FILE_SPL(".spl", "application/futuresplash"),
FILE_SPP(".spp", "text/xml"),
FILE_SSM(".ssm", "application/streamingmedia"),
FILE_SST(".sst", "application/vnd.ms-pki.certstore"),
FILE_STL(".stl", "application/vnd.ms-pki.stl"),
FILE_STM(".stm", "text/html"),
FILE_STY(".sty", "application/x-sty"),
FILE_SVG(".svg", "text/xml"),
FILE_SWF(".swf", "application/x-shockwave-flash"),
FILE_TDF(".tdf", "application/x-tdf"),
FILE_TG4(".tg4", "application/x-tg4"),
FILE_TGA(".tga", "application/x-tga"),
FILE_TIF(".tif", "image/tiff"),
FILE_TIFF(".tiff", "image/tiff"),
FILE_TLD(".tld", "text/xml"),
FILE_TOP(".top", "drawing/x-top"),
FILE_TORRENT(".torrent", "application/x-bittorrent"),
FILE_TSD(".tsd", "text/xml"),
FILE_TXT(".txt", "text/plain"),
FILE_UIN(".uin", "application/x-icq"),
FILE_ULS(".uls", "text/iuls"),
FILE_VCF(".vcf", "text/x-vcard"),
FILE_VDA(".vda", "application/x-vda"),
FILE_VDX(".vdx", "application/vnd.visio"),
FILE_VML(".vml", "text/xml"),
FILE_VPG(".vpg", "application/x-vpeg005"),
FILE_VSD(".vsd", "application/vnd.visio"),
FILE_VSS(".vss", "application/vnd.visio"),
FILE_VST(".vst", "application/vnd.visio"),
FILE_VSW(".vsw", "application/vnd.visio"),
FILE_VSX(".vsx", "application/vnd.visio"),
FILE_VTX(".vtx", "application/vnd.visio"),
FILE_VXML(".vxml", "text/xml"),
FILE_WAV(".wav", "audio/wav"),
FILE_WAX(".wax", "audio/x-ms-wax"),
FILE_WB1(".wb1", "application/x-wb1"),
FILE_WB2(".wb2", "application/x-wb2"),
FILE_WB3(".wb3", "application/x-wb3"),
FILE_WBMP(".wbmp", "image/vnd.wap.wbmp"),
FILE_WIZ(".wiz", "application/msword"),
FILE_WK3(".wk3", "application/x-wk3"),
FILE_WK4(".wk4", "application/x-wk4"),
FILE_WKQ(".wkq", "application/x-wkq"),
FILE_WKS(".wks", "application/x-wks"),
FILE_WM(".wm", "video/x-ms-wm"),
FILE_WMA(".wma", "audio/x-ms-wma"),
FILE_WMD(".wmd", "application/x-ms-wmd"),
FILE_WMF(".wmf", "application/x-wmf"),
FILE_WML(".wml", "text/vnd.wap.wml"),
FILE_WMV(".wmv", "video/x-ms-wmv"),
FILE_WMX(".wmx", "video/x-ms-wmx"),
FILE_WMZ(".wmz", "application/x-ms-wmz"),
FILE_WP6(".wp6", "application/x-wp6"),
FILE_WPD(".wpd", "application/x-wpd"),
FILE_WPG(".wpg", "application/x-wpg"),
FILE_WPL(".wpl", "application/vnd.ms-wpl"),
FILE_WQ1(".wq1", "application/x-wq1"),
FILE_WR1(".wr1", "application/x-wr1"),
FILE_WRI(".wri", "application/x-wri"),
FILE_WRK(".wrk", "application/x-wrk"),
FILE_WS(".ws", "application/x-ws"),
FILE_WS2(".ws2", "application/x-ws"),
FILE_WSC(".wsc", "text/scriptlet"),
FILE_WSDL(".wsdl", "text/xml"),
FILE_WVX(".wvx", "video/x-ms-wvx"),
FILE_XDP(".xdp", "application/vnd.adobe.xdp"),
FILE_XDR(".xdr", "text/xml"),
FILE_XFD(".xfd", "application/vnd.adobe.xfd"),
FILE_XFDF(".xfdf", "application/vnd.adobe.xfdf"),
FILE_XHTML(".xhtml", "text/html"),
FILE_XLS(".xls", "application/x-xls"),
FILE_XLW(".xlw", "application/x-xlw"),
FILE_XML(".xml", "text/xml"),
FILE_XPL(".xpl", "audio/scpls"),
FILE_XQ(".xq", "text/xml"),
FILE_XQL(".xql", "text/xml"),
FILE_XQUERY(".xquery", "text/xml"),
FILE_XSD(".xsd", "text/xml"),
FILE_XSL(".xsl", "text/xml"),
FILE_XSLT(".xslt", "text/xml"),
FILE_XWD(".xwd", "application/x-xwd"),
FILE_X_B(".x_b", "application/x-x_b"),
FILE_X_T(".x_t", "application/x-x_t"),
;
private String extension;
private String contentType;
FileMimeEnums(String extension, String contentType) {
this.extension = extension;
this.contentType = contentType;
}
public String getExtension() {
return extension;
}
public String getContentType() {
return contentType;
}
public Map<String, String> convertToMap() {
Map<String, String> map = new HashMap<>();
Arrays.stream(FileMimeEnums.values()).forEach(item -> {
map.put(item.getExtension(), item.getContentType());
});
return map;
}
}
几乎包含常见和罕见的文件格式以及对应Java下载Mime流类型,类的最后我写了一个枚举转Map的方法,可以去匹配,记得大小写问题~~~