Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 80756 invoked by uid 500); 8 Nov 2002 18:37:29 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 80743 invoked from network); 8 Nov 2002 18:37:28 -0000 Message-ID: <002301c28755$ade57060$c243e39e@BIPA194> From: "Oskar Casquero" To: References: <20021108141650.55631.qmail@web40812.mail.yahoo.com> Subject: Re: multipart HTTP and stream generator Date: Fri, 8 Nov 2002 19:34:00 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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" To: 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: > > > autosave-uploads > false > > > 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 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" > > To: > > 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 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