判断上传的文件是否图片格式

阅读更多

 

转自 http://stackoverflow.com/questions/4169713/how-to-check-a-uploaded-file-whether-it-is-a-image-or-other-file

public void uploadImg(HttpServletRequest req, HttpServletResponse resp) {
	MultipartHttpServletRequest multipartReq = (MultipartHttpServletRequest) req;
	MultipartFile multipartFile = multipartReq.getFile("upload");
	String fileNameOriginal = multipartFile.getOriginalFilename();// 文件原名
	String mimeType = req.getServletContext().getMimeType(fileNameOriginal);
		if (mimeType.startsWith("image/")) {
			// It's an image.
		}
}

 

 

判断视频

http://stackoverflow.com/questions/22601430/how-to-find-the-mime-type-of-video-files-in-java

你可能感兴趣的:(判断,图片,格式)