How to limit download size in Wicket

How to limit file size when uploading to Apache Wicket version 1.4?

I use FileUploadField to handle loading with a regular form without any Ajax data. Is it enough to use Form.setMaxSize () to limit the size of the uploaded file?

If the file is too large, the browser will download the entire file and Wicket will generate a verification error message using the [form-id].uploadTooLarge .

But how does Wicket handle this situation internally by creating temporary files, etc.?

I would like to prevent the case when a user uploads a file with several GB, which is not suitable for memory or disk, while Wicket is processing the request.

+4
source share
3 answers

I did a few digits at the gate of svn and found that the file was actually written to the disk FileUploadBase.parseRequest (RequestContext ctx) . This class checks the file size before writing any of them to disk.

Checking the file size ultimately uses javax.servlet.ServletRequest.getContentLength () to determine the file size, which means that the actual implementation depends on which servlet container you use; but I would say that it is safe to assume that anyone who wrote the servlet version knew enough to get the file size from the header instead of writing it all to disk and then checking its size. This way, you don’t have to worry about people trying to download huge files using all your disk space.

+4
source

The Form documentation says:

In case of a download error, two resource keys are available to indicate error messages: uploadTooLarge and uploadFailed, i.e. in [page] .properties [form-id] .uploadTooLarge = You have uploaded a file that is above the 2 MB limit

My guess is those who are fired in the form of sending confirmation. Have you tried to find out if this is so?

+4
source
 form.setMaxSize(Bytes.kilobytes(fileUploadMaximumKilobytes)); 
+2
source

All Articles