[Catalyst] Catalyst::Response - send a file

Dermot paikkos at googlemail.com
Tue Aug 19 15:11:31 BST 2008


2008/8/19 Bogdan Lucaciu <bogdan at wiz.ro>:
> On Tuesday 19 August 2008 16:41:40 Carl Franks wrote:
>> You'll still need the body($fh) bit to send the data, too.
> Or, if you use Catalyst::Plugin::Static::Simple, you can use:
>
> $c->serve_static_file($file_path);
>
> some code snippets from that method:
>
>    $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 );


Thanx Carl, Bogdan and Oliver for your responses. Sorry if I wasn't
clear to begin with.

This method will work well for binary files. I have opted
$c->response->header() method for now.

Much appreciated.
Dp.



More information about the Catalyst mailing list