//限制允许上传的格式
private static final String[] IMAGE_TYPE=new String[] {".bmp",".jpg",".jpeg","gif",".png"};
@RequestMapping(value="/upload",method=RequestMethod.POST)
@ResponseBody
public String upload(@RequestParam("uploadFile") MultipartFile uploadFile,HttpServletResponse response) throws Exception{
//校验图片格式
boolean isLegal=false;
for(String type:IMAGE_TYPE){ //获取上传的文件名
if(StringUtils.endsWithIgnoreCase(uploadFile.getOriginalFilename(), type)){
isLegal=true;
break;
}
private static final String[] IMAGE_TYPE=new String[] {".bmp",".jpg",".jpeg","gif",".png"};
@RequestMapping(value="/upload",method=RequestMethod.POST)
@ResponseBody
public String upload(@RequestParam("uploadFile") MultipartFile uploadFile,HttpServletResponse response) throws Exception{
//校验图片格式
boolean isLegal=false;
for(String type:IMAGE_TYPE){ //获取上传的文件名
if(StringUtils.endsWithIgnoreCase(uploadFile.getOriginalFilename(), type)){
isLegal=true;
break;
}
}
}