[Catalyst] Force file download

Danijel Milicevic Danijel.Milicevic at rawmode.org
Fri Jul 29 19:01:10 CEST 2005


Here is an alternative to Andy's solution (mine is more hackish thou):

package MyApp::C::MyController;
use Class::DBI::ToCSV; # unreleased module by Miyagawa

sub export : Local {
    my ( $self, $c ) = @_;
    my $csv;
    my $iter = MyApp::M::DBIx::Registrations->retrieve_all;
    open(FILE, "+<", \$csv);
    while ( my $entry = $iter->next ) {
        $entry->to_csv(ForCSV => \*FILE);
    }
    $csv =~ s/,/;/g; # depends what seperator you want really
    $c->res->body($csv);
    $c->res->headers->header( "Content-type" => 'text/csv');
    $c->res->headers->header( "Content-Disposition" => 'attachment;
                               filename=registrations.csv');
}

Regards,
Danijel Milicevic




More information about the Catalyst mailing list