Package com.jalios.jcms.restv2
Class RestV2UploadUtil
java.lang.Object
com.jalios.jcms.restv2.RestV2UploadUtil
Utility class for handling multipart file uploads in REST V2 endpoints.
This class provides helper methods to:
- Extract uploaded files from multipart requests
- Retrieve and decode file names from HTTP headers
- Extract JSON payloads from multipart requests
- Populate
DocUploadHandlerusing query parameters - Build user-friendly error messages for upload failures
It also ensures safe handling of uploaded files by:
- Normalizing file names
- Sanitizing invalid characters
- Storing files in a dedicated temporary directory
All methods are static and designed to be used in REST resource classes handling multipart/form-data requests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildUploadErrorMessage(Map<String, String> failedMap) static StringextractFileNameFromHeaders(javax.ws.rs.core.MultivaluedMap<String, String> headers, org.apache.log4j.Logger logger) Extracts the file name from multipart HTTP headers.static StringextractJsonPayload(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput input, org.apache.log4j.Logger logger) static FileextractUploadedFile(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput input, org.apache.log4j.Logger logger) Extracts the uploaded file from a multipart request and stores it in a temporary directory.static voidpopulateFormHandler(DocUploadHandler formHandler, DocUploadRequestParams params, javax.ws.rs.core.UriInfo uriInfo, String jsonValue)
-
Constructor Details
-
RestV2UploadUtil
public RestV2UploadUtil()
-
-
Method Details
-
extractFileNameFromHeaders
public static String extractFileNameFromHeaders(javax.ws.rs.core.MultivaluedMap<String, String> headers, org.apache.log4j.Logger logger) Extracts the file name from multipart HTTP headers.The method first attempts to read the
Content-Dispositionheader. If not available, it falls back to theContent-Typeheader. The extracted filename is then decoded if needed.- Parameters:
headers- the HTTP headers of the multipart partlogger- the logger used for debug logging- Returns:
- the extracted file name, or
nullif not found - Throws:
javax.ws.rs.WebApplicationException- if header parsing or decoding fails
-
extractUploadedFile
public static File extractUploadedFile(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput input, org.apache.log4j.Logger logger) Extracts the uploaded file from a multipart request and stores it in a temporary directory.The file name is sanitized to prevent invalid characters and normalized to ensure consistent encoding.
- Parameters:
input- the multipart form data inputlogger- the logger used for debug logging- Returns:
- the temporary file, or
nullif no file part is present - Throws:
javax.ws.rs.WebApplicationException- if file processing fails
-
populateFormHandler
public static void populateFormHandler(DocUploadHandler formHandler, DocUploadRequestParams params, javax.ws.rs.core.UriInfo uriInfo, String jsonValue) -
extractJsonPayload
public static String extractJsonPayload(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput input, org.apache.log4j.Logger logger) -
buildUploadErrorMessage
-