You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ml...@editronics-edu.fr on 2002/12/04 17:04:48 UTC

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


Re: How may I get the FilePart object ?

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
mleroux@editronics-edu.fr wrote:

>    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 ?
>  
>

Cocoon uploads the file to a temporary directory and sets the name of 
the file as the corresponding request parameter value.

Example :
<input type="file" name="foo">

Java code :
File uploadedFile = new File(request.getParameter("foo"));

Hope this helps
Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



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


Re: How may I get the FilePart object ?

Posted by Oskar Casquero <jt...@bi.ehu.es>.
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: <ml...@editronics-edu.fr>
To: <co...@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:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@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:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: AW: How may I get the FilePart object ?

Posted by Geoff Howard <co...@yahoo.com>.
Those changes were made after the 2.0.3 release. 
You'll need to either check 2.0.3 branch out of cvs,
or wait for the imminent 2.0.4 release.

However, you can also configure cocoon to totally
ignore all file uploads by changing the
request-factory implementation in web.xml.  

Look for: 
    <init-param>
      <param-name>request-factory</param-name>
     
<param-value>org.apache.cocoon.components.request.MultipartRequestFactoryImpl</param-value>
    </init-param>

And change the param-value to
org.apache.cocoon.components.request.SimpleRequestFactoryImpl

Geoff Howard

--- Tobias Maile <me...@haus-wg.de> wrote:
> 
> 
>   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).
> 
>   [Tobias] I can't find the parameter
> "autosave-upload" in WEB-INF/web.xml
> in Cocoon 2.0.3?
>   Did you know how to cancel the auto upload?
>   Thanks Tobias
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


AW: How may I get the FilePart object ?

Posted by Tobias Maile <me...@haus-wg.de>.

  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).

  [Tobias] I can't find the parameter "autosave-upload" in WEB-INF/web.xml
in Cocoon 2.0.3?
  Did you know how to cancel the auto upload?
  Thanks Tobias

Re: How may I get the FilePart object ?

Posted by Oskar Casquero <jt...@bi.ehu.es>.
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: <ml...@editronics-edu.fr>
To: <co...@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:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>