public static String getOriginalFileName ( Part part ) { String contentDisposition = part . getHeader ( "content-disposition" ) ; if ( contentDisposition != null ) { for ( String cd : contentDisposition . split ( ";" ) ) { if ( cd . trim ( ) . startsWith ( "filename" ) ) { String path = cd . substring ( cd . indexOf ( ' ' ) + 1 ) . replaceAll ( "\"" , "" ) . trim ( ) ; Path filename = Paths . get ( path ) . getFileName ( ) ; return StringUtils . hasText ( filename . toString ( ) ) ? filename . toString ( ) : null ; } } } return null ; }
Get the filename of an uploaded file