cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oskar Casquero" <jtaca...@bi.ehu.es>
Subject Re: How may I get the FilePart object ?
Date Wed, 04 Dec 2002 18:29:56 GMT
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: <mleroux@editronics-edu.fr>
To: <cocoon-users@xml.apache.org>
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:     <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>
>


---------------------------------------------------------------------
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:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message