[Catalyst] Out of Memory - File delivery issue

Craig Chant craig at homeloanpartnership.com
Thu May 2 12:50:44 GMT 2013

Thanks, I have done all that, but it just won't work?

In my controller I have....

            Content_Type =>  'application/vnd.ms-excel',
            Content_Disposition => 'attachment;filename=NBCS_Export.csv'

in my model I have a Moose attribute which is the response object and print or write (tried both) direct to it with..


But all I get in the browser is the textual output?

Do you have to use..

            Content_Type =>  'application/vnd.ms-excel',
            Content_Disposition => 'attachment;filename=NBCS_Export.csv'

Prior to writing to the response IO::File hande?

I have the header output once the result of the XLS output is known (have some or an error) in the controller, but it seems because the output being put in $self->res is performed first in the model before the headers are outputted in the controller, the headers are ignored.

Does this mean I now have to output the headers in my model as well?

And if so, why is my model outputting the view?

Help understanding this is appreciated, as I'm rather confused at the moment.



-----Original Message-----
From: neil.lunn [mailto:neil at mylunn.id.au]
Sent: 02 May 2013 13:29
To: The elegant MVC web framework
Subject: Re: [Catalyst] Out of Memory - File delivery issue

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.

List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by the Financial Conduct Authority.

More information about the Catalyst mailing list