[Catalyst] Catalyst::Response - send a file

Dermot paikkos at googlemail.com
Tue Aug 19 21:04:50 BST 2008

2008/8/19 Jonathan Rockway <jon at jrock.us>:
> * On Tue, Aug 19 2008, Dermot wrote:

>    $c->res->headers->content_type( $type );
>    $c->res->headers->content_length( $stat->size );
>    $c->res->headers->last_modified( $stat->mtime );
> ..
>        my $fh = IO::File->new( $full_path, 'r' );
> ..
>            binmode $fh;
>            $c->res->body( $fh );

>> 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.

Please don't quote me out of context. The "This" referred to Bogdan
Lucaciu reply which was directly above my comments which you have

> 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.
> 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?

As per Carl Franks 2nd reply

> $c->response->header(
>    'Content-Disposition' => "attachment;filename=$name"
> );
> You'll still need the body($fh) bit to send the data, too.

$c->response has headers and header.


I opted for the header method as stated by Carl Franks.


More information about the Catalyst mailing list