验证上传文件类型是否属于图片格式

/**
  * 验证上传文件类型是否属于图片格式
  * @return
  */
  public static boolean validateImageFileType ( FormFile formfile ){
   if ( formfile != null && formfile . getFileSize ()> 0 ){
    List < String > arrowType = Arrays . asList ( "image/bmp" , "image/png" , "image/gif" , "image/jpg" , "image/jpeg" , "image/pjpeg" );
    List < String > arrowExtension = Arrays . asList ( "gif" , "jpg" , "bmp" , "png" );
    String ext = getExt ( formfile );
    return arrowType . contains ( formfile . getContentType (). toLowerCase ()) && arrowExtension . contains ( ext );
   }
   return true ;

 }



publicstaticString getExt(FormFile formfile){
  return formfile.getFileName().substring(formfile.getFileName().lastIndexOf('.')+1).toLowerCase();
 }

你可能感兴趣的:(验证上传文件类型是否属于图片格式)