I am using apache commons-fileupload
to upload file. But, I'm unable to pass more information about the attachment. For example, users want to add attachment information while uploading the particular file. So I send the comments together with attachment. But use commons-fileupload, I only get the attachment, but I can not get the comments. The code below is the form
<form action"taskcontroller" method="post" enctype="multipart/form-data">
<label for="filename_1">File: </label>
<input id="filename_1" type="file" name="filename_1" size="50"/><br/>
comments:<input type='text' name='comments' />
<input type="submit" value="upload" name="command" />
</form>
and the code below is to process the request,
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField()) { //ignore the form element
String fileName = item.getName();
// TODO filesize int is it ok?
int size = (int) item.getSize();
String root = "";//Set the root
File path = new File(root + "/uploads");
if (!path.exists()) {
boolean status = path.mkdirs();
}
item.write(uploadedFile); //write file to disk
}
}
}
but i can not get comments information...