Josep Riudavets wrote:
Hi Geoff....

I have been trying to develope a system to upload a file to cocoon (I'm
using cocoon 2.1) ... but I have not achieved it !!!

Tell me more about what you have tried so far and exactly what you want to accomplish.


I need some help, because I don't understant wiki explanation. I know flow
is not very easy to implement ... but can it be done with an action?

Flow is not that hard. The point I was making was the wiki mentions an upload handler that doesn't exist (because everyone wants to do something different with their upload). You don't have to do it with a component lookup to an upload handler. Let me know what you want to do and I can give you a quick example which will work and advice on how to improve it. Do you just want to save it to a directory on disk?


This can be done with an action but not with an existing action. I'd really recommend going with flow.

Could somebody explain me more about uploading files in Cocoon 2.1 ????

The big thing to remember is you are not uploading them. Cocoon has already handled all the work for you and gives you a way to get the contents of the file as an InputStream (or potentially as a java.io.File) reference. Both of those will be gone automatically at the end of the request though unless you do something with them, as you are trying to do now.


Geoff


----- Original Message ----- From: "Geoff Howard" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 15, 2003 1:52 AM Subject: Re: Uploading fiiles: flow function



Josep Riudavets Aguilo wrote:


Hi all ...

I'm delevoping some code in Cocoon 2.1 in order to upload files.

I have added these lines into my XSL page:

<form action="/upload" method="POST" enctype="multipart/form-data">
    <input type="file" name="blah"/>
    <input type="submit" name="action" value="Upload"/>
   </form>

Next, I have added this code into the sitemap.xmap:

  <map:match pattern="/upload">
   <map:call function="upload"/>
  </map:match>

Now ... I have to write next function:

var role = Packages.org.mystuff.UploadManager.ROLE;

  function upload() {
     var uploader = cocoon.componentManager.getComponent(role);
     var part = cocoon.request.get("blah");
     var success = uploader.handle(part.getInputStream());
     if (success) {
sendPage("success.html");
     } else {
sendPage("failure.html");
     }
  }

But I don't know where to write this function !!! Is is a javascript
function???

(all info is from
http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithFlow)

It's flowscript which, yes, is implemented in Cocoon using the javascript core from the Rhino project. You'll need to read up at least a little on the wiki about flow before making much sense of this. That was an example snippet, not a cut-and-paste ready solution.

For instance, it presupposes that you have a component written and
deployed in Cocoon called org.mystuff.UploadManager and you also have a
pipeline which matches "success.html" and "failure.html".  oh, and it
presupposes that org.mystuff.UploadManager has a public method
handle(InputStream is).

I think this is going to be so common that it would probably deserve to
be in the core at least in a simple form.  I'll see if I can make some
time for it.  This is really pretty easy and would be a good simple
patch for someone who is interested.  I'd be happy to help out.

Geoff


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



Reply via email to