commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Favata <michael.j.fav...@gmail.com>
Subject PortletFileUpload Returning Empty List
Date Tue, 13 Sep 2005 02:18:12 GMT
I recently downloaded the nightly build (9/11/2005) of commons-fileupload 
and I am having a problem using PortletFileUpload. I am running Jetspeed 2 
on Tomcat 5.5.9. I am also using the MVCPortlet framework. 

I am returned an empty list when I invoke the parseRequest method offered by 
the PortletFileUpload class. After a few frustrating hours I downloaded the 
commons-fileupload source and noticed that a MalformedStreamException is 
being buried in the skipPreamble method offered by the 
org.apache.commons.fileupload.MultipartStream class:

try {
// Discard all data up to the delimiter.
discardBodyData();

// Read boundary - if succeded, the stream contains an
// encapsulation.
return readBoundary();
} catch (MalformedStreamException e) {
return false;
}

The encapsulated message in the exception is: 
org.apache.commons.fileupload.MultipartStream$MalformedStreamException:Stream
ended unexpectedly

The JSP I am using to submit my html form is as follows:

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ListIterator" %>
<%@include file="common_imports.jsp" %>
<% 
PortletURL o_upload_action_url = rRes.createActionURL();
o_upload_action_url.setParameter( "request_type", "UploadMedia" );

PortletURL o_go_back_render_url = rRes.createRenderURL();
o_go_back_render_url.setParameter("request_type", "ViewIndex");
%>

<%@include file="sys_message.jsp" %>

<center>
<h3>Upload Media</h3><br>

<form name="upload_media" action="<%= o_upload_action_url%>" method="POST" 
enctype="multipart/form-data">
<B>Upload Single File:</B> Use this upload option if you are uploading a 
single file.<br>
<input type="file" size="32" name="file" ><br><br>
<input type="checkbox" name="checkbox_share">Share to Public<br>
<input type="submit" value="Upload"><br> 
</form>

[<b><a href="<%= o_go_back_render_url%>">Go Back</a></b>]

</center>


An excerpt of the Java code I am using to extract the uploaded file:

public String process(ActionRequest _o_request, ActionResponse _o_response, 
ActionConfig _o_config)
throws PortletException, IOException
{

...

PortletFileUpload o_upload = new PortletFileUpload( new 
DiskFileItemFactory() );
o_upload.setHeaderEncoding( PortletFileUpload.MULTIPART_FORM_DATA );

try
{
List l_items = o_upload.parseRequest( _o_request );

FileItem o_file_item = (FileItem) l_items.get( 0 );
}

...

Inspecting the list returned from the parseRequest method using a debugger 
always yields an empty list. Perhaps there is a configuration entry in 
either Tomcat or Jetspeed 2 that allows/disallows multipart file uploads? If 
anyone has any ideas it would be greatly appreciated. Thank you in 
advance!!!

-- 
Michael J. Favata
AIM: MjFavata

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message