Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 453 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to limit upload file size in Wicket

#1
How to limit file size in uploads in <a href="http://wicket.apache.org/">Apache Wicket</a> version 1.4?

I am using <a href="http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/upload/FileUploadField.html">FileUploadField</a> to handle upload with normal form submit without any Ajax stuff. Is it enough to use <a href="http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/Form.html#getMaxSize()">Form.setMaxSize()</a> to limit the size of uploaded file?

If too large file is uploaded, the browser will upload the whole file and Wicket will create validation error message with key `[form-id].uploadTooLarge`.

But how Wicket internally handles this situation, creating temporary files etc?

I'd like to prevent a case where user uploads file of several GBs that doesn't fit to memory or disk while Wicket handles the request.

Reply

#2
The documentation on Form says:

> In case of an upload error two
> resource keys are available to specify
> error messages: uploadTooLarge and
> uploadFailed ie in [page].properties
> [form-id].uploadTooLarge=You have
> uploaded a file that is over the
> allowed limit of 2Mb

My guess is those get fired in form submit validation..
Have you tried to see if this is the case?
Reply

#3
form.setMaxSize(Bytes.kilobytes(fileUploadMaximumKilobytes));
Reply

#4
I did some digging in the wicket [repository][1] and found that the file is actually written to disk by [FileUploadBase.parseRequest(RequestContext ctx)][2]. This class checks the file size before writing any of it to disk.

The file size check ultimately uses javax.servlet.ServletRequest.getContentLength() to determine the size of the file, which means the actual implementation varies based on what servlet container you use; but, I'd say it's safe to assume that anyone who has written a servlet implementation knew enough to get the file size from the header instead of writing the whole thing to disk and then checking its size. So, you do not have to worry about folks trying to upload huge files using up all your disk space.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through