Question

I have an issue understanding the setMaxUploadSize method. I thought it is supposed to limit the file size. However, if I set the maxUploadSize to 10 bytes, just for testing purpose and then I upload a 10bytes file, the file is rejected and a MaxUploadSizeExceededException is thrown.

Looking in the code for commons-fileupload I understand that it first tests the Content-Length header. Since the Content-Lenght is 224 in my case, the upload is rejected.

So my question is: is the request body size limited or the size of the actual file?

Was it helpful?

Solution

CommonsMultipartResolver is MultipartResolver implementation for Jakarta Commons DiskFileUpload. DiskFileUpload has 2 fields: 1) sizeMax - maximum allowed size of a complete request. 2) fileSizeMax - maximum allowed size of a single uploaded file.

CommonsMultipartResolver implements maxUploadSize field as:

    public void setMaxUploadSize(long maxUploadSize) {
    this.fileUpload.setSizeMax(maxUploadSize);
}

which explains the reason for your exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top