Uploading files in Spring+Wicket

2019-07-06 05:54发布

问题:


What are the steps required for enabling a Java web application (Developed using Spring + Wicket) to accept client file uploads to a specific directory on the server.
While Googling for answers to this question I see suggestions that /WEB-INF/some-directory should be used as the upload location?
Is the reason for this best practice?
Is this location writable by the web application?
What happens to this location when a new version of the web application is deployed? Can/Should any other directory be used?
Thanks

回答1:

Two possible reasons for the use of a subdirectory of WEB-INF:

  • it is not visible through HTTP

  • your application typically has write access to it

I would rather recommend using a configurable, external directory (e.g configured in a context parameter or en application config file); this way you have fine grained control over the permissions of the directory.

AFAIK, file upload in Wicket is provided by the FileUploadField component, which gives you a FileUpload object that you can writeTo a file on your server.

You might also want to configure/check the maximum size for the files you want to accept. In Tomcat, this is done through the maxPostSize attribute of a Connector (see The HTTP Connector)