|
From: John L. <jl...@ar...> - 2005-11-05 04:45:00
|
Yujin,
Good to hear from you again! Sorry I missed your post the first time.
Multisupport is on my list of things to round out the portlet
framework. Jeff Tan-Ang has reportedly already done a prototype of the
integration and should be sending me something shortly. I should be
able to integrate it fairly soon after I get it from him. If you
already have something working, you could send it to me as well.
In the meantime, we already do a simple file upload task in one of our
portlets using commons-fileupload-1.1.dev directly. It is a
SimpleFormController -- here is a simplified version of our
onSubmitAction method where all the file processing takes place:
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 fileItem.getContentType()
}
}
} catch (Exception e) {
// process any relevant exceptions
}
} else {
// no file submitted
}
}
I hope that helps. Stay tuned...
John
Yujin Kim wrote:
>Hello spring developers,
>
>A few weeks ago I posted a question regarding multipart support in
>Portlet MVC and received no response so I am trying again.
>
>The current version of Portlet MVC code doesn't support
>multipart/file-uploading. Looking at how MultipartResolver works in
>Servlet MVC, it appears it's not too insane to port it over to Portlet
>MVC but there seems to be a couple of issues.
>
>1. The package structure in the current set up is very much servlet
>centric which is understandable given that portlet api was release
>much later. But it would still be nice to be able to organize the
>package structure so portlet and servlet mvc can have a parallel
>structure much like the mvc codes.
>
>2. Also commons-fileupload needs to be updated to 1.1-dev which
>includes PortletFileItem which might affect the servlet multipart
>support somewhat due to possible api changes.
>
>I would be more than happy to tackle this and submit a patch for this
>but I am hoping if you can comment on the above points or some
>pointers on how I should structure the packages if package refactoring
>is not a feasible approach (of course I am suggesting this for 1.3,
>the version portlet support was promised.)
>
>Many thanks
>
>Yujin
>
>
>
|