java 上传文件根据后继名对应contentType

发布时间:2022-06-03 07:37:14

在系统上传后,下载时就必须对应上相应的content-type,否则就无法以正确的形式下载文件, 所以我们存储的content-type就必须正确

import java.util.HashMap;

public class MimeConstant {
	//如果有多个相同的charset类型,可以使用""代替或者指定统一的文件类型,指定的语句需要放在所有相同的语句的第一个位置
	//更多类型可以访问  http://tool.oschina.net/commons
	private static HashMap<String,String> mimeMap=new HashMap<String,String>();
	static {
		mimeMap.put(".3gp","video/3gpp");
		mimeMap.put(".asf","video/x-ms-asf");
		mimeMap.put(".avi","video/x-msvideo");
		mimeMap.put(".m4u","video/vnd.mpegurl");
		mimeMap.put(".m4v","video/x-m4v");
		mimeMap.put(".mov","video/quicktime");
		mimeMap.put(".mp4","video/mp4");
		mimeMap.put(".mpg4","video/mp4");
		mimeMap.put(".mpe","video/x-mpeg");
		mimeMap.put(".mpeg","video/mpg");
		mimeMap.put(".mpg","video/mpg");
		mimeMap.put(".m3u","audio/x-mpegurl");
		mimeMap.put(".m4a","audio/mp4a-latm");
		mimeMap.put(".m4b","audio/mp4a-latm");
		mimeMap.put(".m4p","audio/mp4a-latm");
		mimeMap.put(".mp2","x-mpeg");
		mimeMap.put(".mp3","audio/x-mpeg");
		mimeMap.put(".mpga","audio/mpeg");
		mimeMap.put(".ogg","audio/ogg");
		mimeMap.put(".rmvb","audio/x-pn-realaudio");
		mimeMap.put(".wav","audio/x-wav");
		mimeMap.put(".wma","audio/x-ms-wma");
		mimeMap.put(".wmv","audio/x-ms-wmv");
		mimeMap.put(".c","text/plain");
		mimeMap.put(".java","text/plain");
		mimeMap.put(".conf","text/plain");
		mimeMap.put(".cpp","text/plain");
		mimeMap.put(".h","text/plain");
		mimeMap.put(".prop","text/plain");
		mimeMap.put(".rc","text/plain");
		mimeMap.put(".sh","text/plain");
		mimeMap.put(".log","text/plain");
		mimeMap.put(".txt","text/plain");
		mimeMap.put(".xml","text/plain");
		mimeMap.put(".html","text/html");
		mimeMap.put(".htm","text/html");
		mimeMap.put(".css","text/css");
		mimeMap.put(".jpg","image/jpeg");
		mimeMap.put(".jpeg","image/jpeg");
		mimeMap.put(".bmp","image/bmp");
		mimeMap.put(".gif","image/gif");
		mimeMap.put(".png","image/png");
		mimeMap.put("","application/octet-stream");
		mimeMap.put(".bin","application/octet-stream");
		mimeMap.put(".class","application/octet-stream");
		mimeMap.put(".exe","application/octet-stream");
		mimeMap.put("class","application/octet-stream");
		mimeMap.put(".apk","application/vnd.android.package-archive");
		mimeMap.put(".doc","application/msword");
		mimeMap.put(".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
		mimeMap.put(".xls","application/vnd.ms-excel");
		mimeMap.put(".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		mimeMap.put(".gtar","application/x-gtar");
		mimeMap.put(".gz","application/x-gzip");
		mimeMap.put(".jar","application/java-archive");
		mimeMap.put(".js","application/x-javascript");
		mimeMap.put(".mpc","application/vnd.mpohun.certificate");
		mimeMap.put(".msg","application/vnd.ms-outlook");
		mimeMap.put(".pdf","application/pdf");
		mimeMap.put(".pps","application/vnd.ms-powerpoint");
		mimeMap.put(".ppt","application/vnd.ms-powerpoint");
		mimeMap.put(".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation");
		mimeMap.put(".rtf","application/rtf");
		mimeMap.put(".tar","application/x-tar");
		mimeMap.put(".tgz","application/x-compressed");
		mimeMap.put(".wps","application/vnd.ms-works");
		mimeMap.put(".z","application/x-compress");
		mimeMap.put(".zip","application/x-zip-compressed");
	}
}

Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为