cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oskar Casquero" <jtaca...@bi.ehu.es>
Subject Re: multipart HTTP and stream generator
Date Fri, 08 Nov 2002 18:34:00 GMT
So the type of object returned (FilePartFile or FilePartArray) depends on
how you configure autosave-uploads in web-xml. I've updated cocoon-2.1 and
now web.xml file includes autosave-uploads entry.

About the performance, I'm not worried about that. I don't want to save the
file: first, because I don't need it, I just want to get an input stream
from the request; and second, to avoid pipeline problems when I've two
connections that upload a file with the same name. If cocoon can manage
files with the same name, which belong to different connections, without
problems, then I've no problem saving the file temporaly in the server.

Oskar

----- Original Message -----
From: "Geoff Howard" <cocoongeoff@yahoo.com>
To: <cocoon-dev@xml.apache.org>
Sent: Friday, November 08, 2002 3:16 PM
Subject: Re: multipart HTTP and stream generator


> Oskar,
>
> The
> org.apache.cocoon.component.request.multipart.MultipartParser
> will create either a FilePartFile (which is the file
> "part" of the request parsed out and saved to disk) or
> a FilePartArray (same thing, but kept in mem as a
> byte[]) for you automatically before the pipeline
> enters the picture.  To get it to make the Array,
> configure autosave-uploads in web.xml to false, like
> so:
>
>     <init-param>
>       <param-name>autosave-uploads</param-name>
>       <param-value>false</param-value>
>     </init-param>
>
> If that entry doesn't exist in your web.xml, you need
> to get updated source from cvs - this is a recent
> change.  I'm pretty sure that the change is available
> in 2.0.3 as well as 2.1 (which one are you using?)
>
> You can also just delete the FilePartFile after you're
> finished with it.  I think it exposes a File getFile()
> method which you can use.  In the long run, it doesn't
> matter whether it was saved temporarily to disk or not
> (unless there's a performance benefit one way or the
> other).
>
> Good luck,
> Geoff
>
> --- Oskar Casquero <jtacaoio@bi.ehu.es> wrote:
> > 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" <cocoongeoff@yahoo.com>
> > To: <cocoon-dev@xml.apache.org>
> > 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 <jtacaoio@bi.ehu.es> 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:
> > cocoon-dev-unsubscribe@xml.apache.org
> > > For additional commands, email:
> > cocoon-dev-help@xml.apache.org
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > cocoon-dev-unsubscribe@xml.apache.org
> > For additional commands, email:
> > cocoon-dev-help@xml.apache.org
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> U2 on LAUNCH - Exclusive greatest hits videos
> http://launch.yahoo.com/u2
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message