近期使用Bladex对接minio存储,发现通过Bladex上传的图片、文件等的contentType都是默认的application/octet-stream格式,无法直接预览,查看源码发现,在MinioTemplate中将contentType固定写成了application/octet-stream,建议修改支持自动识别文件格式!
示例代码如下:
public class MinioTemplate implements OssTemplate {
/**
* .........
*/
@Override
@SneakyThrows
public BladeFile putFile(String bucketName, String fileName, InputStream stream) {
return putFile(bucketName, fileName, stream, ViewContentType.getContentType(fileName));
}
}
public enum ViewContentType {
DEFAULT("default", "application/octet-stream"),
A001("001", "application/x-001"),
A301("301", "application/x-301"),
A323("323", "text/h323"),
A906("906", "application/x-906"),
A907("907", "drawing/907"),
A11("a11", "application/x-a11"),
ACP("acp", "audio/x-mei-aac"),
AI("ai", "application/postscript"),
AIF("aif", "audio/aiff"),
AIFC("aifc", "audio/aiff"),
AIFF("aiff", "audio/aiff"),
ANV("anv", "application/x-anv"),
ASA("asa", "text/asa"),
ASF("asf", "video/x-ms-asf"),
ASP("asp", "text/asp"),
ASX("asx", "video/x-ms-asf"),
AU("au", "audio/basic"),
AVI("avi", "video/avi"),
AWF("awf", "application/vnd.adobe.workflow"),
BIZ("biz", "text/xml"),
BMP("bmp", "application/x-bmp"),
BOT("bot", "application/x-bot"),
C4T("c4t", "application/x-c4t"),
C90("c90", "application/x-c90"),
CAL("cal", "application/x-cals"),
CAT("cat", "application/s-pki.seccat"),
CDF("cdf", "application/x-netcdf"),
CDR("cdr", "application/x-cdr"),
CEL("cel", "application/x-cel"),
CER("cer", "application/x-x509-ca-cert"),
CG4("cg4", "application/x-g4"),
CGM("cgm", "application/x-cgm"),
CIT("cit", "application/x-cit"),
CLASS("class", "java/*"),
CML("cml", "text/xml"),
CMP("cmp", "application/x-cmp"),
CMX("cmx", "application/x-cmx"),
COT("cot", "application/x-cot"),
CRL("crl", "application/pkix-crl"),
CRT("crt", "application/x-x509-ca-cert"),
CSI("csi", "application/x-csi"),
CSS("css", "text/css"),
CUT("cut", "application/x-cut"),
DBF("dbf", "application/x-dbf"),
DBM("dbm", "application/x-dbm"),
DBX("dbx", "application/x-dbx"),
DCD("dcd", "text/xml"),
DCX("dcx", "application/x-dcx"),
DER("der", "application/x-x509-ca-cert"),
DGN("dgn", "application/x-dgn"),
DIB("dib", "application/x-dib"),
DLL("dll", "application/x-msdownload"),
DOC("doc", "application/msword"),
DOT("dot", "application/msword"),
DRW("drw", "application/x-drw"),
DTD("dtd", "text/xml"),
DWF("dwf", "Model/vnd.dwf"),
DWG("dwg", "application/x-dwg"),
DXB("dxb", "application/x-dxb"),
DXF("dxf", "application/x-dxf"),
EDN("edn", "application/vnd.adobe.edn"),
EMF("emf", "application/x-emf"),
EML("eml", "message/rfc822"),
ENT("ent", "text/xml"),
EPI("epi", "application/x-epi"),
EPS("eps", "application/x-ps"),
ETD("etd", "application/x-ebx"),
EXE("exe", "application/x-msdownload"),
FAX("fax", "image/fax"),
FDF("fdf", "application/vnd.fdf"),
FIF("fif", "application/fractals"),
FO("fo", "text/xml"),
FRM("frm", "application/x-frm"),
G4("g4", "application/x-g4"),
GBR("gbr", "application/x-gbr"),
GCD("gcd", "application/x-gcd"),
GIF("gif", "image/gif"),
GL2("gl2", "application/x-gl2"),
GP4("gp4", "application/x-gp4"),
HGL("hgl", "application/x-hgl"),
HMR("hmr", "application/x-hmr"),
HPG("hpg", "application/x-hpgl"),
HPL("hpl", "application/x-hpl"),
HQX("hqx", "application/mac-binhex40"),
HRF("hrf", "application/x-hrf"),
HTA("hta", "application/hta"),
HTC("htc", "text/x-component"),
HTM("htm", "text/html"),
HTML("html", "text/html"),
HTT("htt", "text/webviewhtml"),
HTX("htx", "text/html"),
ICB("icb", "application/x-icb"),
ICO("ico", "image/x-icon"),
IFF("iff", "application/x-iff"),
IG4("ig4", "application/x-g4"),
IGS("igs", "application/x-igs"),
III("iii", "application/x-iphone"),
IMG("img", "application/x-img"),
INS("ins", "application/x-internet-signup"),
ISP("isp", "application/x-internet-signup"),
IVF("IVF", "video/x-ivf"),
JAVA("java", "java/*"),
JFIF("jfif", "image/jpeg"),
JPE("jpe", "image/jpeg"),
JPEG("jpeg", "image/jpeg"),
JPG("jpg", "image/jpeg"),
JS("js", "application/x-javascript"),
JSP("jsp", "text/html"),
LA1("la1", "audio/x-liquid-file"),
LAR("lar", "application/x-laplayer-reg"),
LATEX("latex", "application/x-latex"),
LAVS("lavs", "audio/x-liquid-secure"),
LBM("lbm", "application/x-lbm"),
LMSFF("lmsff", "audio/x-la-lms"),
LS("ls", "application/x-javascript"),
LTR("ltr", "application/x-ltr"),
M1V("m1v", "video/x-mpeg"),
M2V("m2v", "video/x-mpeg"),
M3U("m3u", "audio/mpegurl"),
M4E("m4e", "video/mpeg4"),
MAC("mac", "application/x-mac"),
MAN("man", "application/x-troff-man"),
MATH("math", "text/xml"),
MDB("mdb", "application/x-mdb"),
MFP("mfp", "application/x-shockwave-flash"),
MHT("mht", "message/rfc822"),
MHTML("mhtml", "message/rfc822"),
MI("mi", "application/x-mi"),
MID("mid", "audio/mid"),
MIDI("midi", "audio/mid"),
MIL("mil", "application/x-mil"),
MML("mml", "text/xml"),
MND("mnd", "audio/x-musicnet-download"),
MNS("mns", "audio/x-musicnet-stream"),
MOCHA("mocha", "application/x-javascript"),
MOVIE("movie", "video/x-sgi-movie"),
MP1("mp1", "audio/mp1"),
MP2("mp2", "audio/mp2"),
MP2V("mp2v", "video/mpeg"),
MP3("mp3", "audio/mp3"),
MP4("mp4", "video/mp4"),
MPA("mpa", "video/x-mpg"),
MPD("mpd", "application/-project"),
MPE("mpe", "video/x-mpeg"),
MPEG("mpeg", "video/mpg"),
MPG("mpg", "video/mpg"),
MPGA("mpga", "audio/rn-mpeg"),
MPP("mpp", "application/-project"),
MPS("mps", "video/x-mpeg"),
MPT("mpt", "application/-project"),
MPV("mpv", "video/mpg"),
MPV2("mpv2", "video/mpeg"),
MPW("mpw", "application/s-project"),
MPX("mpx", "application/-project"),
MTX("mtx", "text/xml"),
MXP("mxp", "application/x-mmxp"),
NET("net", "image/pnetvue"),
NRF("nrf", "application/x-nrf"),
NWS("nws", "message/rfc822"),
ODC("odc", "text/x-ms-odc"),
OUT("out", "application/x-out"),
P10("p10", "application/pkcs10"),
P12("p12", "application/x-pkcs12"),
P7B("p7b", "application/x-pkcs7-certificates"),
P7C("p7c", "application/pkcs7-mime"),
P7M("p7m", "application/pkcs7-mime"),
P7R("p7r", "application/x-pkcs7-certreqresp"),
P7S("p7s", "application/pkcs7-signature"),
PC5("pc5", "application/x-pc5"),
PCI("pci", "application/x-pci"),
PCL("pcl", "application/x-pcl"),
PCX("pcx", "application/x-pcx"),
PDF("pdf", "application/pdf"),
PDX("pdx", "application/vnd.adobe.pdx"),
PFX("pfx", "application/x-pkcs12"),
PGL("pgl", "application/x-pgl"),
PIC("pic", "application/x-pic"),
PKO("pko", "application-pki.pko"),
PL("pl", "application/x-perl"),
PLG("plg", "text/html"),
PLS("pls", "audio/scpls"),
PLT("plt", "application/x-plt"),
PNG("png", "image/png"),
POT("pot", "applications-powerpoint"),
PPA("ppa", "application/vs-powerpoint"),
PPM("ppm", "application/x-ppm"),
PPS("pps", "application-powerpoint"),
PPT("ppt", "applications-powerpoint"),
PR("pr", "application/x-pr"),
PRF("prf", "application/pics-rules"),
PRN("prn", "application/x-prn"),
PRT("prt", "application/x-prt"),
PS("ps", "application/postscript"),
PTN("ptn", "application/x-ptn"),
PWZ("pwz", "application/powerpoint"),
R3T("r3t", "text/vnd.rn-realtext3d"),
RA("ra", "audio/vnd.rn-realaudio"),
RAM("ram", "audio/x-pn-realaudio"),
RAS("ras", "application/x-ras"),
RAT("rat", "application/rat-file"),
RDF("rdf", "text/xml"),
REC("rec", "application/vnd.rn-recording"),
RED("red", "application/x-red"),
RGB("rgb", "application/x-rgb"),
RJS("rjs", "application/vnd.rn-realsystem-rjs"),
RJT("rjt", "application/vnd.rn-realsystem-rjt"),
RLC("rlc", "application/x-rlc"),
RLE("rle", "application/x-rle"),
RM("rm", "application/vnd.rn-realmedia"),
RMF("rmf", "application/vnd.adobe.rmf"),
RMI("rmi", "audio/mid"),
RMJ("rmj", "application/vnd.rn-realsystem-rmj"),
RMM("rmm", "audio/x-pn-realaudio"),
RMP("rmp", "application/vnd.rn-rn_music_package"),
RMS("rms", "application/vnd.rn-realmedia-secure"),
RMVB("rmvb", "application/vnd.rn-realmedia-vbr"),
RMX("rmx", "application/vnd.rn-realsystem-rmx"),
RNX("rnx", "application/vnd.rn-realplayer"),
RP("rp", "image/vnd.rn-realpix"),
RPM("rpm", "audio/x-pn-realaudio-plugin"),
RSML("rsml", "application/vnd.rn-rsml"),
RT("rt", "text/vnd.rn-realtext"),
RTF("rtf", "application/x-rtf"),
RV("rv", "video/vnd.rn-realvideo"),
SAM("sam", "application/x-sam"),
SAT("sat", "application/x-sat"),
SDP("sdp", "application/sdp"),
SDW("sdw", "application/x-sdw"),
SIT("sit", "application/x-stuffit"),
SLB("slb", "application/x-slb"),
SLD("sld", "application/x-sld"),
SLK("slk", "drawing/x-slk"),
SMI("smi", "application/smil"),
SMIL("smil", "application/smil"),
SMK("smk", "application/x-smk"),
SND("snd", "audio/basic"),
SOL("sol", "text/plain"),
SOR("sor", "text/plain"),
SPC("spc", "application/x-pkcs7-certificates"),
SPL("spl", "application/futuresplash"),
SPP("spp", "text/xml"),
SSM("ssm", "application/streamingmedia"),
SST("sst", "application-pki.certstore"),
STL("stl", "application/-pki.stl"),
STM("stm", "text/html"),
STY("sty", "application/x-sty"),
SVG("svg", "text/xml"),
SWF("swf", "application/x-shockwave-flash"),
TDF("tdf", "application/x-tdf"),
TG4("tg4", "application/x-tg4"),
TGA("tga", "application/x-tga"),
TIF("tif", "image/tiff"),
TIFF("tiff", "image/tiff"),
TLD("tld", "text/xml"),
TOP("top", "drawing/x-top"),
TORRENT("torrent", "application/x-bittorrent"),
TSD("tsd", "text/xml"),
TXT("txt", "text/plain"),
UIN("uin", "application/x-icq"),
ULS("uls", "text/iuls"),
VCF("vcf", "text/x-vcard"),
VDA("vda", "application/x-vda"),
VDX("vdx", "application/vnd.visio"),
VML("vml", "text/xml"),
VPG("vpg", "application/x-vpeg005"),
VSD("vsd", "application/x-vsd"),
VSS("vss", "application/vnd.visio"),
VST("vst", "application/x-vst"),
VSW("vsw", "application/vnd.visio"),
VSX("vsx", "application/vnd.visio"),
VTX("vtx", "application/vnd.visio"),
VXML("vxml", "text/xml"),
WAV("wav", "audio/wav"),
WAX("wax", "audio/x-ms-wax"),
WB1("wb1", "application/x-wb1"),
WB2("wb2", "application/x-wb2"),
WB3("wb3", "application/x-wb3"),
WBMP("wbmp", "image/vnd.wap.wbmp"),
WIZ("wiz", "application/msword"),
WK3("wk3", "application/x-wk3"),
WK4("wk4", "application/x-wk4"),
WKQ("wkq", "application/x-wkq"),
WKS("wks", "application/x-wks"),
WM("wm", "video/x-ms-wm"),
WMA("wma", "audio/x-ms-wma"),
WMD("wmd", "application/x-ms-wmd"),
WMF("wmf", "application/x-wmf"),
WML("wml", "text/vnd.wap.wml"),
WMV("wmv", "video/x-ms-wmv"),
WMX("wmx", "video/x-ms-wmx"),
WMZ("wmz", "application/x-ms-wmz"),
WP6("wp6", "application/x-wp6"),
WPD("wpd", "application/x-wpd"),
WPG("wpg", "application/x-wpg"),
WPL("wpl", "application/-wpl"),
WQ1("wq1", "application/x-wq1"),
WR1("wr1", "application/x-wr1"),
WRI("wri", "application/x-wri"),
WRK("wrk", "application/x-wrk"),
WS("ws", "application/x-ws"),
WS2("ws2", "application/x-ws"),
WSC("wsc", "text/scriptlet"),
WSDL("wsdl", "text/xml"),
WVX("wvx", "video/x-ms-wvx"),
XDP("xdp", "application/vnd.adobe.xdp"),
XDR("xdr", "text/xml"),
XFD("xfd", "application/vnd.adobe.xfd"),
XFDF("xfdf", "application/vnd.adobe.xfdf"),
XHTML("xhtml", "text/html"),
XLS("xls", "application/x-xls"),
XLW("xlw", "application/x-xlw"),
XML("xml", "text/xml"),
XPL("xpl", "audio/scpls"),
XQ("xq", "text/xml"),
XQL("xql", "text/xml"),
XQUERY("xquery", "text/xml"),
XSD("xsd", "text/xml"),
XSL("xsl", "text/xml"),
XSLT("xslt", "text/xml"),
XWD("xwd", "application/x-xwd"),
X_B("x_b", "application/x-x_b"),
X_T("x_t", "application/x-x_t");
private String prefix;
private String type;
public static String getContentType(String prefix) {
if (StrUtil.isEmpty(prefix)) {
return DEFAULT.getType();
}
prefix = prefix.substring(prefix.lastIndexOf(".") + 1);
for (ViewContentType value : ViewContentType.values()) {
if (prefix.equalsIgnoreCase(value.getPrefix())) {
return value.getType();
}
}
return DEFAULT.getType();
}
ViewContentType(String prefix, String type) {
this.prefix = prefix;
this.type = type;
}
public String getPrefix() {
return prefix;
}
public String getType() {
return type;
}
}
扫一扫访问 Blade技术社区 移动端