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
_Preferred_
- Ensure that {{fileUpload }} Interceptor is included in the Action's stack.
The default stack already includes {{fileUpload }}.
- Ensure that the HTML form sets the
enctype
and specifies on or more file type inputs.
...
Code Block | ||||
---|---|---|---|---|
| ||||
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 | |
struts.multipart.maxSize | Approximately 2M |
...