Package org.primefaces.util
Class FileUploadUtils
java.lang.Object
org.primefaces.util.FileUploadUtils
Utilities for FileUpload components.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Characterprotected static StringconvertJavaScriptRegex(String jsRegex) Converts a JavaScript regular expression like '/(\.|\/)(gif|jpeg|jpg|png)$/i' to the Java usable format '(\\.|\\/)(gif|jpeg|jpg|png)$'static StringformatAllowTypes(String allowTypes) Formats the allowTypes regex pattern in a more human-friendly format.static StringformatBytes(Long bytes, Locale locale) static <T extends javax.servlet.http.HttpServletRequest>
PathgetChunkDir(T request) static <T extends javax.servlet.http.HttpServletRequest>
FileUploadChunkDecoder<T>getFileUploadChunkDecoder(T request) static <T extends javax.servlet.http.HttpServletRequest>
StringgetWebkitRelativePath(T request) static booleanisValidType(PrimeApplicationContext context, UploadedFile uploadedFile, String allowTypes, String accept) Check if an uploaded file meets all specifications regarding its filename and content type.listChunks(Path path) listChunks(T request) static voidperformVirusScan(javax.faces.context.FacesContext facesContext, UploadedFile file) static StringrequireValidFilename(String filename) Checks file name for validity based on Windows or Linux rules.static StringrequireValidFilePath(String filePath, boolean mustExist) Check the file path to ensure its valid and prevent directory traversal security issues.static javax.faces.validator.ValidatorExceptionvalidationError(String message)
-
Method Details
-
requireValidFilename
Checks file name for validity based on Windows or Linux rules.- Parameters:
filename- the name of the file to check- Returns:
- the extracted file name
-
requireValidFilePath
Check the file path to ensure its valid and prevent directory traversal security issues.- Parameters:
filePath- the file path to testmustExist- true if the directory must exist on disk, false if not- Returns:
- the updated file path
-
validationError
-
containsInvalidCharacters
-
isValidType
public static boolean isValidType(PrimeApplicationContext context, UploadedFile uploadedFile, String allowTypes, String accept) Check if an uploaded file meets all specifications regarding its filename and content type. It evaluates allowTypes as well as accept and uses the installedFileTypeDetectorimplementation. For most reliable content type checking it's recommended to plug in Apache Tika as an implementation.- Parameters:
context- thePrimeApplicationContextuploadedFile- the details of the uploaded fileallowTypes- the Javascript regexaccept- the accept types- Returns:
true, if all validations regarding filename and content type passed,falseelse
-
convertJavaScriptRegex
Converts a JavaScript regular expression like '/(\.|\/)(gif|jpeg|jpg|png)$/i' to the Java usable format '(\\.|\\/)(gif|jpeg|jpg|png)$'- Parameters:
jsRegex- the client side JavaScript regex- Returns:
- the Java converted version of the regex
-
performVirusScan
public static void performVirusScan(javax.faces.context.FacesContext facesContext, UploadedFile file) throws VirusException - Throws:
VirusException
-
listChunks
-
listChunks
-
getFileUploadChunkDecoder
public static <T extends javax.servlet.http.HttpServletRequest> FileUploadChunkDecoder<T> getFileUploadChunkDecoder(T request) -
getChunkDir
-
getWebkitRelativePath
public static <T extends javax.servlet.http.HttpServletRequest> String getWebkitRelativePath(T request) -
formatAllowTypes
Formats the allowTypes regex pattern in a more human-friendly format.- Parameters:
allowTypes- The allowTypes regex pattern to format- Returns:
- The allowTypes formatted in a more human-friendly format.
-
formatBytes
-