File Upload

Waffle provides support for uploading files, using Commons FileUpload. File uploads are abstracted by Waffle's org.codehaus.waffle.io.FileUploader interface which can be declared as dependency by the controllers. Waffle provides a request-based implementation.

Let's walk through an example. The controller would simply declare the dependency: The RequestFileUploader needs to be registered in at request scope, along with any dependency it needs. A few comments are in order:

  • By default, Waffle adopts the PRG pattern, which for request-scoped controllers would not allow the content of the request to be made available to the view, because it would be redirected to a new request. Hence, we disable it via the @PRG annotation to show the uploaded files in the referring view.
  • Waffle honours to the FileUpload interfaces, which allows the implementations and the configuration to be controlled by the user via the registrar. In particular, Waffle by default uses FileUpload's resource cleanup mechanism, detailed in the user guide.