[Catalyst] Catalyst::Response - send a file

Carl Franks fireartist at gmail.com
Tue Aug 19 12:52:17 BST 2008


2008/8/19 Dermot <paikkos at googlemail.com>:
> Hi,
>
> I am looking for a method to send a file in response to a request. My
> effort is below and all this does is print the file's path on the
> page. I can't set the content-disposition or see find an obvious
> method in C::Response or C::Request.
>
> Am I looking in the wrong place? Can someone point me in the right direction.
> Tia,
> Dp.
>
>
>
> sub downloadFile {
>
>  my ($name, $filepath) = @_;
>
>  my $length = (stat($filepath))[7];
>  my $res = $c->response;
>  $res->content_length($length);
>
>  $res->headers->({ 'Content-Disposition' =>
> "attachment;filename=$name"} ); # CODE ref error
>
>  $res->sendfile($filepath,0,$length); # Ok no such method but
> hopefully you'll get what I mean.
>
> }

open my $filehandle, '<', $filepath
    or die $!;

$c->response->body( $filehandle );


Cheers,
Carl



More information about the Catalyst mailing list