Here is an example to download files to a local directory with Cocoon 2.1 Final release. To be more specific, I'll show you how to pop up a downloading box instead of displaying a document into the browser.

I've tried two different methods. There is no need to configure Cocoon particularly. All is made in the sitemap.

<map:pipeline>
  <map:match pattern="save/*">
    <map:act type="header">
      <map:parameter name="Cache-Control" value="Pragma:no-cache" />
      <map:parameter name="Content-Disposition" value="attachment ; filename={1}.xml" />
    </map:act>
    <map:read type="resource" mime-type="binary/octet-stream" src="{1}.xml">
       <map:parameter name="format" value="xml"/>
    </map:read>
  </map:match>
</map:pipeline>

I this pipeline, you don't have to create custom sitemap components.

To do that, use the HttpHeaderAction (don't forget to declare it). Let's see the different options :

"Cache-Control" is used to tell not to use the cache.

"Content-disposition" is used to define the document as an attachment and to specify a filename. You can set any name you want with any extension.

I'm not sure parameter "format" as an influence.

<map:pipeline>
  <map:match pattern="save/*">
   <map:act type="header">
     <map:parameter name="Cache-Control" value="Pragma:no-cache" />
     <map:parameter name="Content-Disposition" value="attachment ; filename={1}.xml" />
   </map:act>
   <map:generate type="file" src="{1}.xml" />
   <map:serialize type="xml"/>
  </map:match>
</map:pipeline>

This works with IE, mozilla and firebird. Be careful to remove your cache and to reload your browser. If it's not working reopen you're browser.

Lionel Crine

DownloadFilesToLocalDisk (last edited 2009-09-20 23:41:30 by localhost)