cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
Subject How to use the file uploading mechanism in cocoon
Date Fri, 04 Apr 2003 15:13:49 GMT
Start with the following page

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

the hook the /upload URL to a flow function

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

   <map:match pattern="/*.html">
    <map:read src="{1}.html"/>
   </map:match>

then write the flow 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");
      }
   }

alternatively, you can write the following java code in your sitemap 
components

  import org.apache.cocoon.servlet.multipart.*;

  ...

  Request request = ObjectModelHelper.getRequest(obj);
  if (request instanceof MultipartHttpServletRequest) {
    Part part = (Part) request.get("blah");
    if (part != null) {
      // do something with it
    } else {
      // parameter not found
    }
  } else {
    // upload is disabled
  }

Hope this helps (and gets thru)

-- 
Stefano.



Mime
View raw message