The FilePart object represents the uploaded file. Depending on how you
configure "autosave-upload" parameter in WEB-INF/web.xml cocoon returns a
FilePartFile (the file is written to disk; autosave-upload=true) or a
FilePartArray (the file is in memory; autosave-upload=false).

Here is the code snippet I add to the StreamGenerator to manage multipart
http requests:

Request req = ObjectModelHelper.getRequest(objectModel);

} else if (contentType.startsWith("multipart/form-data")) {
    String myParameter = parameters.getParameter(FILE_NAME, null);
    if (myParameter == null) {
        throw new ProcessingException("StreamGenerator expects a sitemap
parameter called '" + FILE_NAME + "' for handling form data");
    }
    FilePart filePart = (FilePart)req.get(myParameter);  /* or FilePartArray
filePart = (FilePartArray)req.get(myParameter); */
    InputStream is = filePart.getInputStream();
    inputSource = new InputSource(is);

This only works with autosave-upload=false, so the FilePart object is a
FilePartArray object. If you want want to save the file in the disk you must
turn on autosave-uploading and do this:

    FilePartFile filePart = (FilePartFile)req.get(myParameter);
    InputStream is = filePart.getInputStream();
    inputSource = new InputSource(is);

Oskar

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 04, 2002 5:04 PM
Subject: How may I get the FilePart object ?


>
>     Hi !
>
>
> I'm trying to use automatic upload with cocoon 2.0.3 (with jboss, jetty,
> Linux red hat).
> I've read that cocoon uploads the file and puts a FilePart object inside
the
> request.
>
> So my question is :
> How can I get this object inside my Java code ?
>
>
>    Michael
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to