I am having trouble with uploading files using Infragistics jQuery igUpload. Their control has a nice interface with multi file capability and progress bars etc. I'm sure this can work but I must have something configured wrong.
The igUpload control has a uploadURL param that I set to a servlet. (maybe this is mistake #1?) A nicely formatted POST msg is sent with the expected params, header, and file to be uploaded in a multipart/form-data. My servlet gets the request and processes it like this :
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Check that we have a file upload request
if ( ServletFileUpload.isMultipartContent(request) ) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
ServletContext servletContext = this.getServletConfig().getServletContext();
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List<FileItem> items = upload.parseRequest(request);
for ( FileItem fi : items ) {
String name = fi.getName(); // NEVER executed
}
}
The problem is that the FileItem list is always empty. In Eclipse debug, if I dig down into the request, I do see DiskFileItem objects, all filled in with the files already uploaded to
C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\work\Catalina\localhost\MyApp
so I guess this means that something else already uploaded the files.
From this post File upload with ServletFileUpload's parseRequest? the answer was "this is most likely because you have parsed the request already before. The files are part of the request body and you can parse it only one time." and "You was right. looks like struts2 fileupload plugin is already reading in between."
This appears to be whats happening to me. So how do I fix this?
- Should the igUpload control point to a struts action URL instead?
- Should (can) I disable the struts2 file upload plugin somehow so that my Servlet can do the uploading?
- Should I use another package to parse or manually do through the HttpServletRequest and process the DiskFileItems as they are already designated?
Thanks for any insight.