I am developing a module which supports upload of a text file which should be parsed later. I am trying to retrieve an uploaded file in my controller, but although it does recognize multipart form data submission, the file is not available.
In my JSP I have a form field:
<form method="post" enctype="multipart/form-data"> Select file to upload: <input type="file" name="my_file"/><br/><br/> <input type="submit" value="Upload File" name="uploadButton" /> </form>
I am trying to access the file in the controller like this:
boolean isMultipart = ServletFileUpload.isMultipartContent(request);//this gives TRUE DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(new File("/tmp")); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request);
isMultipart is “TRUE” so it does recognize a file is submitted, but the size of items is 0.