0

I'm reading the official and unofficial docs for MultipartConfig, but I don't understand the use of its parameters, specially these ones:

MaxFileSize: The maximum size allowed for uploaded files, in bytes. If the size of any uploaded file is greater than this size, the web container will throw an exception (IllegalStateException). The default size is unlimited.

fileSizeThreshold: The file size in bytes after which the file will be temporarily stored on disk. The default size is 0 bytes.

maxRequestSize: The maximum size allowed for a multipart/form-data request, in bytes. The web container will throw an exception if the overall size of all uploaded files exceeds this threshold. The default size is unlimited.

I think MaxFileSize is the value for the maximum file size, isn't it? But... what about the other 2 parameters? Could anyone explain me them in other words?

Thanks!

Ommadawn
  • 2,450
  • 3
  • 24
  • 48

1 Answers1

1

fileSizeThreshold: The file size in bytes after which the file will be temporarily stored on disk. The default size is 0 bytes.

The uploaded file can reside in server's memory or be stored to disk in some temp location, this setting is the threshold between the two states.

maxRequestSize: The maximum size allowed for a multipart/form-data request, in bytes. The web container will throw an exception if the overall size of all uploaded files exceeds this threshold. The default size is unlimited.

One multipart request might contain a bunch of small files, that's the total limit = the sum of all the uploaded files sizes.

borowis
  • 1,207
  • 10
  • 17
  • I understand the "maxRequestSize" :) If I use 1MB for fileSizeThreshold parameter, does it mean that will be 1MB of reserved RAM memory to store the file and if the file is above 1MB it will be stored in the hard disk? That's what I've understood from your words. – Ommadawn Mar 16 '17 at 20:29
  • there will be no reserved memory, files above 1MB will be stored on disk, and files below will be in RAM, if your server runs out of memory because of that it will just crash. But need to check source code for each particular application server because they might have bugs / not respect the documentation etc. – borowis Mar 16 '17 at 20:57
  • If you want to limit to 300kB the max file size, which filesizethreshold should you use? – Ommadawn Mar 16 '17 at 21:40
  • I'd use `307200` – borowis Mar 16 '17 at 23:05