I realized that Apache Tomcat allows the following configuration: in a hard-coded or annotated approach. I am not sure if the maximum file size is calculated during the upload process or after the file is uploaded to a temporary location. The documentation states the following:
The @MultipartConfig annotation supports the following optional attributes:
location: The absolute path to the directory in the file system. the location attribute does not support the path relative to the application context. This place is used for temporary storage of files, details are processed or when the file size exceeds the specified fileSizeThreshold. The default location is "".
fileSizeThreshold: file size in bytes, after which the file will be temporarily stored on disk. The default size is 0 bytes.
MaxFileSize: the maximum size allowed for uploaded files, in bytes. If the size of any downloaded file is larger than this size, the container will throw an exception (IllegalStateException) on the Internet. The default size is unlimited.
maxRequestSize: the maximum size allowed for a given multipart / form request, in bytes. The web container will throw an exception if the total size of all downloaded files exceeds this threshold. The default size is unlimited.
annotation approach:
@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)
I appreciate this if anyone can clarify whether MaxFileSize is computed during the boot process and how to handle this exception in the servlet.