客户端和服务端验证上传图片限制

来源:互联网 发布:java调用adb命令 编辑:程序博客网 时间:2024/06/16 15:08

客户端:

var logofile = form.logofile.value;
 if(trim(form.name.value)!=""){
         var ext = logofile.substring(logofile.length-3).toLowerCase();
         if(ext != "jpg"&&ext != "gif"&& ext != "bmp" &&ext != "png"){
                  alert("只允许上传gif、bmp、jpg、png格式的文件");
                  return false;
             }
  }

 

 

 

 

 

 

 

 

服务端:

 

public static boolean validateFileType(FormFile formFile){
  if(formFile != null && formFile.getFileSize()>0){
   List<String> arrowType = Arrays.asList("image/bmp","image/jpg","image/png","image/gif","image/jpeg"
     ,"image/pjpeg");
   return arrowType.contains(formFile.getContentType().toLowerCase());
  }
  return true;
 }

原创粉丝点击