[Catalyst] Out of Memory - File delivery issue

neil.lunn neil at mylunn.id.au
Thu May 2 12:29:08 GMT 2013

On 2/05/2013 10:07 PM, Craig Chant wrote:
> Hi Neil,
> My model is already 'Catalyst::Model::Factory::PerRequest'
> So I have added an attribute...
> sub prepare_arguments {
>      my ($self,$c) = @_;
>      return {,
>          res         =>  $c->res
>      };
> }
> So I now have my model bound to  $c->res
> How do I assign the scalar CSV data to it?
Assuming now there is an accessor in the actual class you are using for 
the model, and assuming a Moose based class then rather than putting the 
CSV output into a scalar you want to use the 'response' object. 
Something like:

$self->res->print( $my_line_of_csv );

At any rate it's how the CSV is being output in the model that you need 
to change.
> Surely if I use $self->res->body($xls) in the model it's no different than doing it in the  Controller and is still going to fall over with 'Out of memory'?
Yep. This is why the discussion says do it line by line rather than 
build a big scalar.
> I seem to be getting no-where trying to print direct to the browser...
> I've tried..
>          $c->response->header(
>              Content_Type =>  'application/vnd.ms-excel',
>              Content_Disposition => 'attachment;filename=NBCS_Export.csv'
>              );

That part's okay. You need a response Content_Type.

More information about the Catalyst mailing list