Class JakartaStreamMultiPartRequest
- All Implemented Interfaces:
MultiPartRequest
For more details see WW-3025
- Since:
- 2.3.18
-
Field Summary
Fields inherited from class org.apache.struts2.dispatcher.multipart.AbstractMultiPartRequest
BUFFER_SIZE, bufferSize, defaultEncoding, errors, maxFiles, maxFileSize, maxSize, maxSizeOfFiles, maxStringLength, parameters, STRUTS_MESSAGES_UPLOAD_ERROR_PARAMETER_TOO_LONG_KEY, uploadedFiles -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Longprotected voidcreateUploadedFile(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file) Creates anUploadedFileabstraction over an uploaded file.protected voidprocessFileItemAsFileField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, Path location) Processes a file field from the multipart request using streaming API.protected voidprocessFileItemAsFormField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput) Processes a normal form field (non-file) from the multipart request using streaming API.protected voidprocessUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) Processes the upload.protected voidstreamFileToDisk(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file) Streams the file upload stream to the specified file.Methods inherited from class org.apache.struts2.dispatcher.multipart.AbstractMultiPartRequest
buildErrorMessage, cleanUp, createJakartaFileUpload, createRequestContext, createTemporaryFile, deleteFile, exceedsMaxStringLength, getCanonicalName, getContentType, getErrors, getFile, getFileNames, getFileParameterNames, getFilesystemName, getParameter, getParameterNames, getParameterValues, parse, prepareServletFileUpload, readCharsetEncoding, rejectEmptyFile, setBufferSize, setDefaultEncoding, setMaxFiles, setMaxFileSize, setMaxSize, setMaxSizeOfFiles, setMaxStringLength
-
Constructor Details
-
JakartaStreamMultiPartRequest
public JakartaStreamMultiPartRequest()
-
-
Method Details
-
processUpload
protected void processUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException Processes the upload.- Specified by:
processUploadin classAbstractMultiPartRequest- Parameters:
request- the servlet requestsaveDir- location of the save dir- Throws:
IOException
-
processFileItemAsFormField
protected void processFileItemAsFormField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput) throws IOException Processes a normal form field (non-file) from the multipart request using streaming API.This method handles text form fields by:
- Validating the field name is not null
- Reading the field value from the input stream
- Checking if the field value exceeds maximum string length
- Adding the value to the parameters collection
Fields with null names are skipped with a warning log message.
The streaming approach is more memory-efficient for large form data.
- Parameters:
fileItemInput- a form field item input from the streaming API- Throws:
IOException- if an error occurs reading the input stream- See Also:
-
readStream(InputStream)AbstractMultiPartRequest.exceedsMaxStringLength(String, String)
-
actualSizeOfUploadedFiles
- Returns:
- actual size of already uploaded files
-
processFileItemAsFileField
protected void processFileItemAsFileField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, Path location) throws IOException Processes a file field from the multipart request using streaming API.This method handles file uploads by:
- Validating the file name and field name are not null/empty
- Checking if the upload exceeds maximum file count
- Creating a temporary file in the specified location
- Streaming the file content directly to disk
- Checking if the total size exceeds maximum allowed size
- Creating an
UploadedFileabstraction or cleaning up on size exceeded
Files with null names or field names are skipped with appropriate logging.
The streaming approach is more memory-efficient for large file uploads as it writes directly to disk rather than loading into memory first.
- Parameters:
fileItemInput- file item representing upload file from streaming APIlocation- the directory where temporary files will be created- Throws:
IOException- if an error occurs during file processing- See Also:
-
streamFileToDisk
protected void streamFileToDisk(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file) throws IOException Streams the file upload stream to the specified file.- Parameters:
fileItemInput- file item inputfile- the file- Throws:
IOException
-
createUploadedFile
protected void createUploadedFile(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file) Creates anUploadedFileabstraction over an uploaded file.This method creates a wrapper around the uploaded file that provides a consistent interface for accessing file information and content. The created
UploadedFileinstance contains:- The original filename as provided by the client
- The content type (MIME type) if available
- The form field name that contained the file
- A reference to the temporary file on disk
The file is automatically added to the uploaded files collection, grouped by field name to support multiple file uploads per field.
- Parameters:
fileItemInput- file item stream containing file metadatafile- the temporary file containing the uploaded content- See Also:
-