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

    xiaoxiao2021-12-15  4

    /**   * 验证上传文件类型是否属于图片格式   * @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();  }

    转载请注明原文地址: https://ju.6miu.com/read-1000279.html

    最新回复(0)