Skip to main content

4.7.1 Form Upload

Hasor includes Apache FileUpload internally and simplifies and optimizes it. Therefore, when using Hasor file upload, you do not need to introduce any third-party jar.

To use file upload, you must operate through the WebController class. The following is a file upload example:

Example
@MappingTo("/fileupload.do")
public class FileUpLoad extends WebController {
@Any
public void execute() throws IOException {
for (FileItem multipart : this.getMultipart("upfile")) {
multipart.writeTo(...);
multipart.deleteOrSkip();
}
}
}

The corresponding HTML page is an ordinary upload form, but note that the enctype attribute of the form tag must be changed to multipart/form-data.

<form action="/fileupload.do" method="post" enctype="multipart/form-data">
<input type="file" name="upfile"/>
<input type="submit" value="Upload"/>
</form>