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]