Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

You can obtain the MultipartRequestWrapper from the ServletActionContext or by utilizing the fileUpload interceptor. The fileUpload interceptor is preferred.

Note

See the file upload page for more examples and advanced configuration

Ask the ServletActionContext

Code Block
MultipartRequestWrapper multipartRequest = ((MultipartRequestWrapper)ServletActionContext.getRequest())

The MultipartRequestWrapper provideds access methods such as getFiles, getFile, getContentType, hasErrors, getErrors, and so forth, so that you can process the file uploaded.

Utilize the fileUpload Interceptor

(star) _Preferred_

  • Ensure that {{fileUpload }} Interceptor is included in the Action's stack.
    • (info) The default stack already includes {{fileUpload }}.
  • Ensure that the HTML form sets the enctype and specifies on or more file type inputs.

...

Code Block
java
java
public File getMyDoc()
public ContentTypeString setMyDocContentTypegetMyDocContentType()
public String setMyDocFileNamegetMyDocFileName()

Handling multiple files

When multiple files are uploaded by a form, the files are represented by an array.

...

The uploaded files can be handled by iterating through the appropriate array.

Extra Information

Property

Default

struts.multipart.parser

Commons FileUpload

struts.multipart.saveDir

javax.servlet.context.tempdir as defined by container

struts.multipart.maxSize

Approximately 2M

...