|
Jonathan,
> Hello
all.
> I wanted to know
if I am able to use the MultipartRequestWrapper object by itself.
> That is, can I
store MultipartRequestWrapper objects in a bean.
I would definately not recommend it. The
MultipartRequestWrapper object is
something that
should be
used internally to Struts, to work around some existing issues
between
normal and multipart
requests. Also, that class is definately going to change to
extend
javax.servlet.http.HttpServletRequestWrapper when
Struts adopts the Servlet 2.3 spec.
> My purpose is to
temporarily store a binary and its file name in a bean until
> the final form page
when the user submits the whole "kit and
kaboodle".
Instead of doing this,
you'd probably just want to stick to using an ActionForm bean that
has
a FormFile
property. The FormFile interface should suit your needs well, as
it has a getFileName()
method and methods to
retrieve the data written to a temporary file after
uploading:
public
class MultipageForm extends ActionForm {
private FormFile
theFile;
public void setTheFile(FormFile file) {
this.theFile
= file;
}
public FormFile getTheFile()
{
return theFile;
}
}
> Part of the
problem is that I dont understand what is going on. It looks like the
request keeps the following:
> "name" property
representing the form field name
> "value" property
representing the String path of the file you uploaded
> some binary
Stream data representing the file
Again, don't pay much
attention to the MultipartRequestWrapper class, concentrate on creating
an
ActionForm bean
that has a org.apache.struts.upload.FormFile property representing your
file, and
normal String properties
representing your form data, just as you would normally create a
non
multipart
form.
> I realy have no
idea, and I am looking around for answers but am coming up
empty.
> Can someone sum
up what is happening here, what the request contains, what values the
request
> works with, and
what are the requirements.
Martin Cooper summed
this up nicely in another thread about uploading, but I'll go
over it anyway:
1) Request comes in,
Struts goes to populate the form (BeanUtils.populate()) discovers
that the
content type of the request
is "multipart/form-data"
2) Struts goes to
populate the form, and creates a MultipartRequestHandler instance to
handle
the multipart request.
MultipartRequestHandler is an interface, the implementation can
change
at will and can be specified as an
init-param for ActionServlet, or as an ActionServlet
property
in
struts-config.xml
2a) In the
implementation that comes with Struts, the multipart form data is read as
follows:
Read the
data,
if it's a
string parameter, grab it's value and put it in a Hashtable for later
use
if it's a
file, read the file with a BufferedInputStream and store the data in a
temporary
file, then
wrap it in a FormFile implementation
(org.apache.struts.upload.DiskFile)
and hand it
back to BeanUtils (next step)
3)
BeanUtils.populate() uses the interface methods in MultipartRequestHandler to
grab the properties
that were retrieved from the normal
multipart request, the populates your ActionForm bean with
the
relevant
data.
4) The Action
is executed, and code in there manipulates the file according to whatever you
want to
do with it, for example, say we
wanted to take the previous form bean (above) and use it in the
action:
public class
UploadAction extends Action {
public ActionForward
perform(ActionMapping
mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response) {
FormFile theFile = ((MultipageForm) form).getTheFile();
String filename = theFile.getFileName();
//and
so on...
}
Hope this helps, also consult that long thread
called
"uploading files requires immediate serialization?",
Martin Cooper does
a damn good job of answering questions about
this. Thanks again Martin...
- Mike
|
RE: Concepts in working with multipart request
SCHACHTER,MICHAEL (HP-NewJersey,ex2) Mon, 11 Jun 2001 18:52:39 -0700
- Concepts in working with multipart re... Jonathan
- Re: Concepts in working with mul... SCHACHTER,MICHAEL (HP-NewJersey,ex2)
- Re: Concepts in working with... Jonathan Asbell

