|
From: John L. <jl...@ar...> - 2005-11-09 19:56:32
|
The main issue with integrating Multipart support into Spring Portlet MVC is the need for commons-fileupload-1.1 for JSR-168 support. I've talked with Juergen about this and we agree that we do not want to update Spring's use of commons-fileupload until some kind of release gets pushed out. I (and several others) have asked the maintainers of commons-fileupload about their plans for a 1.1 release. I was directed to a 20 Oct 2005 posting from Martin Cooper on the commons-dev mailing list. In that posting he states that there is no formal release plan yet, but he is hopeful to spend some time on it soon. You can see the complete posting here: http://www.mail-archive.com/com...@ja.../msg68563.html Given the lack of specificity around a 1.1 release, we are going to put integration of Multipart support for Spring Portlet MVC on hold for now. Once commons-fileupload-1.1 is released, then we will formally integrate it into Spring. Until this happens, you can either use a custom version of the appropriate classes or utilize commons-fileupload-1.1-dev directly yourself. The latter option is actually quite simple. As an example, here is a simplified version of an onSubmitAction method for a SimpleFormController that handles a file upload: protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command, BindException errors) throws ServletException, IOException { PortletRequestContext prc = new PortletRequestContext(request); boolean isMultiPart = FileUpload.isMultipartContent(prc); if (isMultiPart) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(getMaxFileSize()); PortletFileUpload upload = new PortletFileUpload(factory); try { List fileItems = upload.parseRequest(request); for (Iterator i = fileItems.iterator(); i.hasNext();) { FileItem fileItem = (FileItem) i.next(); if (!"".equals(fileItem.getName()) && fileItem.getSize() > 0 ) { byte array[] = new byte[(int)fileItem.getSize()]; fileItem.getInputStream().read(array); // do something here to save the array // and possibly use fileItem.getContentType() } } } catch (Exception e) { // process any relevant exceptions } } else { // no file submitted } } Please send me any feedback about this. John Lewis |