Class RestV2UploadUtil

java.lang.Object
com.jalios.jcms.restv2.RestV2UploadUtil

public class RestV2UploadUtil extends Object
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 DocUploadHandler using 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 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-Disposition header. If not available, it falls back to the Content-Type header. The extracted filename is then decoded if needed.

      Parameters:
      headers - the HTTP headers of the multipart part
      logger - the logger used for debug logging
      Returns:
      the extracted file name, or null if 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 input
      logger - the logger used for debug logging
      Returns:
      the temporary file, or null if 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

      public static String buildUploadErrorMessage(Map<String,String> failedMap)