java上传图⽚格式限制_限制上传图⽚⼤⼩,格式为jpg或者
getsavefilename
png
在Constants.java中:
public static HashMap getPhotoTypeMap() {
HashMap resultMap = new HashMap();
resultMap.put("jpg", "");
resultMap.put("png", "");
return resultMap;
}
@RequestMapping(value = "/uploadAvatarImage", method = RequestMethod.POST)
public String uploadAvatarImage(Model uiModel, @RequestParam("avatarImageFile") MultipartFile file) {
String OriginalFilename();
if (!"".OriginalFilename()) && Size() <= Constants.SYSTEM_IMAGE_MAX_SIZE) {
String type=originalFileName.substring(originalFileName.lastIndexOf(".")+1);
if (!PhotoTypeMap().LowerCase())) {
uiModel.addAttribute("validateMessage", "The format of the image is not supported, you can only upload the format of jpg or png.");
return showProfile(uiModel,"Y");
}
}
if (file == null || Size() <= 0) {
uiModel.addAttribute("validateMessage", "The image size can not be zero.");
return showProfile(uiModel,"Y");
}
if (Size() > Constants.SYSTEM_IMAGE_MAX_SIZE) {
uiModel.addAttribute("validateMessage", "The image size can not exceed 1024K.");
return showProfile(uiModel,"Y");
}
try {
UploadFile uploadThumbnailImage = Tools.uploadImageWithThumbnail(file,
Constants.UPLOADFILE_HOMEOWNER_AVATAR_PATH, Constants.SYSTEM_THUMBNAIL_IMAGE_WIDTH,
Constants.SYSTEM_THUMBNAIL_IMAGE_HEIGHT);
if (uploadThumbnailImage != null) {
User currentUser = getCurrentUser();
uploadThumbnailImage.setUser(currentUser);
uploadThumbnailImage.setCategory(Constants.UPLOADFILE_AVATAR_TYPE); uploadFileService.saveUploadImage(uploadThumbnailImage);
}
} catch (IOException e) {
e.printStackTrace();
}
showProfile(uiModel,"N");
return "redirect:/homeowner/profile";
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。