[Catalyst] Catalyst::Response - send a file

Wade.Stuart at fallon.com Wade.Stuart at fallon.com
Tue Aug 19 20:40:20 BST 2008


Jonathan Rockway <jon at jrock.us> wrote on 08/19/2008 01:20:53 PM:

> * On Tue, Aug 19 2008, Dermot wrote:
> > This method will work well for binary files. I have opted
> > $c->response->header() method for now.
>
> You haven't described what that method is.
>
> There are two things you need to do to send a file for download.
>
> 1) Set up the HTTP headers (Content-disposition) so that the browser
>    knows what to do.

For the save to disk force prompt -- code I that has served me well in the
past (for all tested browsers, ie mac, ie 5->7, moz, ff 1->2, safari,
opera, lynx, many proxy servers ...)

        $c->res->headers->content_type('application/octet-stream');
        $c->res->headers->content_length( $stat->size );
        $c->res->headers->last_modified( $stat->mtime );
        $c->response->headers->header('Content-disposition:' =>
"attachment; filename=$filename" );
        $c->res->headers->expires( time() );
        $c->res->headers->header( 'Last-Modified' => HTTP::Date::time2str);
        $c->res->headers->header( 'Pragma'        => 'no-cache' );
        $c->res->headers->header( 'Cache-Control' => 'no-cache' );


This forces the save promt and also makes sure no-cache is set so that a
failed download does not leave the user with a partial file.

-Wade


>
> 2) Actually send the data.
>
> In your original post, you hand-waved sending the data.  A number of
> posters told you how to do it.  Now you're saying you've "opted [for
> the] header method".  That doesn't make any sense.
>
> So what exactly are you doing?
>
> Regards,
> Jonathan Rockway
>
> --
> print just => another => perl => hacker => if $,=$"
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list