[dancer-users] send_file and Dancer2

Jacques Lareau jack.lareau at gmail.com
Wed Oct 15 14:41:33 BST 2014


Hi Jean-Marc,

Here is how I do it:

return send_file(
        "/system/path/to/file.xlsx",
        content_type => 'application/vnd.oasis.opendocument.spreadsheet',
        filename => 'excel_file.xlsx',
        system_path => 1
);

If I need more control I use File::Slurp read_file function:

header 'Content-Disposition' => "inline; filename=$filename";
content_type "application/vnd.oasis.opendocument.spreadsheet";

return read_file( "/system/path/to/file.xlsx", binmode => ':raw' );

On Wed, Oct 15, 2014 at 8:42 AM, Jean-Marc Choulet <jm130794 at gmail.com>
wrote:

> Hello,
>
> I 'am new to Dancer2 and I tried to migrate some code from mod_perl to
> Dancer2. Somewhere, I have this mod_perl code :
>
> sub handler {
>     ...
>
>     open my $fh, "<$filename" or die $@;
>     binmode $fh;
>
>     $req->content_type('application/vnd.oasis.opendocument.spreadsheet');
>     $req->headers_out->{'Content-Disposition'} = "attachment;
> filename=$file";
>
>     my ($n, $data);
>     while ($n = read($fh, $data, 1024)) {
>         $req->print($data);
>     }
>
>     close($fh);
>
>     return Apache2::Const::OK;
> }
>
> The mod_perl code send a OpenOffice document to the client.
>
> How can I do the same thing with Dancer2 ?
>
> Thanks,
>
> Jean-Marc
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20141015/6b53d40c/attachment.html>


More information about the dancer-users mailing list