[Catalyst] Out of Memory - File delivery issue

Craig Chant craig at homeloanpartnership.com
Thu May 2 13:08:37 GMT 2013


I can confirm if I output the view in my Model it works?

        # clean due to Catalyst wide chars error
        $xls =~ s/[^[:ascii:]]//gi;

        # output header
        $self->res->header(
            Content_Type =>  'application/vnd.ms-excel',
            Content_Disposition => 'attachment;filename=NBCS_Export.csv'
            );

        # add to Catalyst response object
        $self->res->write($xls);

What's the purpose of MVC in this situation?

I seem to be binding my model to a catalyst object which I was told is wrong in the IRC and then outputting view headers from my model as well.

Is this the only way to get Catalyst to play with simple data streaming?

I get the feeling I'm doing something wrong here and would appreciate guidance.

Regards,

Craig.

-----Original Message-----
From: Craig Chant [mailto:craig at homeloanpartnership.com]
Sent: 02 May 2013 13:51
To: The elegant MVC web framework
Subject: RE: [Catalyst] Out of Memory - File delivery issue

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

In my controller I have....

        $c->response->header(
            Content_Type =>  'application/vnd.ms-excel',
            Content_Disposition => 'attachment;filename=NBCS_Export.csv'
            );
        $c->response->body('');


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

        $self->res->write($xls);
        $self->res->print($xls);

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

Do you have to use..

        $c->response->header(
            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.

Thanks,

Craig.

-----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.

_______________________________________________
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