Thank you Geoff !

With your help and
http://outerthought.net/wiki/Wiki.jsp?page=FileUploadWithAction, finally I
get an stream generator that supports multipart http (for file transfer from
the client to cocoon). The problem is that I don't want cocoon to handle
automatically file updates, so I will have to disable it. An what is more, I
don't want to save the file in the server, just obtain an input stream from
the request and generate SAX events from it. Do you know how to obtain a
FilePartArray object from the HttpServletRequest or Request object? I'm not
able to do it with FilePartArray constructor because it is protected.

Oskar

----- Original Message -----
From: "Geoff Howard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 07, 2002 10:44 PM
Subject: Re: multipart HTTP and stream generator


> I'm not exactly sure I've followed what you're trying
> to do, but are you aware that multipart requests are
> handled automatically by cocoon?  When a file is
> included in a request, the default behaviour is to
> save it to upload-dir under the work directory in
> whatever servlet container you're using.  In tomcat,
> this means
> $TOMCAT_HOME/work/Standalone/localhost/cocoon/cocoon-files/upload-dir
>
> In addition, an
> org.apache.cocoon.components.request.multipart.FilePartFile
> (or FilePartArray - both extend FilePart depending on
> behaviour - see javadocs for info) object is placed in
> the request and can be retrieved by any cocoon
> component with a reference to the request.  FilePart
> defines a method to get the contents of the file as an
> InputStream.  From there you can move it elsewhere on
> disk, put it in a database, or parse it and send the
> sax events down the line, as it sounds like you want
> to do.
>
> HTH,
> Geoff Howard
>
> --- Oskar Casquero <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Has anybody tried to get data from a multipart http
> > request in cocoon? I've modified the stream
> > generator with "marsh" project classes (in
> > sourceForge.net) in order to support multipart http
> > resquest and it doesn't work, but I've also tested
> > the same example in a servlet (outside cocoon) and
> > it works, so I don't know what happens. Where is the
> > problem? Perhaps in HttpServletRequest request =
> > (HttpServletRequest)
> >
> objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);?
> >
> > Oskar
> >
> > Here is the generate method of the modified stream
> > generator:
> > public void generate() throws IOException,
> > SAXException, ProcessingException
> >
> > {
> >
> >     Parser parser = null;
> >
> >     String parameter =
> > parameters.getParameter(MyStreamGenerator.FORM_NAME,
> > null);
> >
> >     String myParameter =
> > parameters.getParameter(MyStreamGenerator.FILE_NAME,
> > null);
> >
> >     int len = 0;
> >
> >     String contentType = null;
> >
> >     try {
> >
> >         HttpServletRequest request =
> > (HttpServletRequest)
> >
> objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
> >
> >         contentType = request.getContentType();
> >
> >         if (contentType == null) {
> >
> >             throw new IOException("Required header
> > ContentType is missing.");
> >
> >         } else if
> >
> (contentType.startsWith("application/x-www-form-urlencoded"))
> > {
> >
> >             String sXml =
> > request.getParameter(parameter);
> >
> >             inputSource = new InputSource(new
> > StringReader(sXml));
> >
> >         } else if
> > (contentType.startsWith("multipart/form-data")) {
> >
> >             // Instantiate and parse the
> > multipart/form-data POST.
> >
> >             MultipartServletRequest mpReq = new
> > MultipartServletRequest(request);
> >
> >             // Get the variables we want from the
> > request, including the file.
> >
> >             MultipartFileInfo fileInfo =
> > mpReq.getFile(myParameter);
> >
> >
> >
> >             InputStream fileIn = fileInfo.getFile();
> >
> >             len = fileInfo.getLength();
> >
> >             PostInputStream anStream = new
> > PostInputStream(request.getInputStream(), len);
> >
> >             inputSource = new InputSource(anStream);
> >
> >
> >         } else if
> > (contentType.startsWith("text/plain") ||
> >
> >             contentType.startsWith("text/xml") ||
> >
> >
> > contentType.startsWith("application/xml")) {
> >
> >             len = request.getContentLength();
> >
> >             if (len > 0) {
> >
> >                 PostInputStream anStream = new
> > PostInputStream(request.getInputStream(), len);
> >
> >                 inputSource = new
> > InputSource(anStream);
> >
> >             } else {
> >
> >                 throw new
> > IOException("getContentLen() == 0");
> >
> >             }
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> U2 on LAUNCH - Exclusive greatest hits videos
> http://launch.yahoo.com/u2
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>


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

Reply via email to