Scott,
Thank you very much. It worked great (after some minor doctoring of course).
In the action handler class, I took out the part where you use the O'Reilly
multipart form class and used the parameter parser that is part of the
rundata object (see below). The FileItem class offers some handy methods
such as write() and getOutputStream().
Calling the extended action class to handle the form submission was a real
eye-opener.
Here is the version I created (doesn't do anything but spit out the file
size to sys.out):
===>
package org.apache.jetspeed.modules.actions;
import org.apache.turbine.modules.actions.*;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
import org.apache.turbine.modules.Action;
import javax.servlet.http.*;
import java.io.IOException;
import org.apache.turbine.util.upload.FileItem;
public class FileUploadAction extends Action
{
public void doPerform(RunData data) throws Exception
{
FileItem file =
data.getParameters().getFileItem("uploadfilename");
System.out.println ("Size of uploaded file from (FileItem)
file.getSize(): " + file.getSize());
}
}
====>
Thanks again,
~spike
-----Original Message-----
From: Scott Williams [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 17, 2001 12:29 PM
To: [EMAIL PROTECTED]
Subject: Re: Multipart Form Submissions
Spike,
I just did what you are trying to do. Here's the
HTML:
<FORM
action='http://<%=host%>:<%=port%>/jetspeed/portal?action=SWFileMoverAction'
METHOD='POST' ENCTYPE='multipart/form-data'
name='browse_form'>
<BR>
Choose a file to upload.
<BR><BR>
<INPUT TYPE=FILE NAME=file1>
<BR><INPUT type='submit' name='submit'
value='Submit'>
</FORM>
Here's the action that I created, SWFileMoverAction:
package org.apache.jetspeed.modules.actions;
import org.apache.turbine.modules.actions.*;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
import org.apache.turbine.modules.Action;
import com.sw.jetspeed.*;
import javax.servlet.http.*;
import java.io.IOException;
import com.oreilly.servlet.MultipartRequest;
/*
* This method is the action for the FileMover
portlet.
*/
public class SWFileMoverAction extends Action
{
private String parent = "";
public void doPerform(RunData data) throws
Exception
{
HttpServletRequest request = data.getRequest();
//begin
try {
MultipartRequest multi =
new MultipartRequest(request,
"C:\\jakarta-tomcat-3.3-m4\\webapps\\test\\Marketing",
10*1024*1024); // 10MB
}
catch (IOException lEx) {
Log.error(lEx + "error reading or saving
file");
}
}
The form is submitted to the action SWFileMoverAction.
The action creates a MultipartRequest which takes the
arguments: request, location to upload file, and the
file size maximum.
HTH,
--- Spike Hains <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to write a jsp portlet that will allow
> jetspeed users to upload
> files and would like to know how to I access the
> file element of a
> multi-part form submission from a jsp portlet?
>
> On submission, I'm doing this in the jsp portlet
> page:
>
> <%
> ...
> RunData data =
>
(RunData)pageContext.getAttributeJspService.RUNDATA,PageContext.REQUEST_SCOP
> E);
> FileItem myfile =
> data.getParameters().getFileItem("uploadfilename");
> ...
> %>
>
> I check 'data' before I try and get the fileitem but
> it is null. Should this
> work? Is there a more appropriate way to handle file
> uploading in jsp
> portlets?
>
> Originally I was going to use O'Reilly's multipart
> form classes and was able
> to upload files in a jsp page OUTSIDE of the
> jetspeed application directory.
> When I would put the same jsp file in a portlet, the
> request object seemed
> empty.
>
> Any input, suggestions or direction is appreciated.
>
> Thanks all,
>
> ~spike
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]