I've been using this for while....

    # check for ok status
    if($result->ok)
    {

        # output header
        $c->response->content_type('application/vnd.ms-excel');
        $c->response->content_length(length($xls));
        $c->response->header(Content_Disposition => 
'attachment;filename=NBCS_Export.csv');

        # create an IO::File for Catalyst
        use IO::File;
        my $iof = IO::File->new;

        # open XLS
        $iof->open(\$xls, "r");

        # output XLS data
        $c->response->body($iof);

        # close file
        undef $iof;
    }

It resolves the out of memory issue if you try to print direct to 
$c->response->body without putting the content in an IO::File object.


From: John Napiorkowski [mailto:[email protected]]
Sent: 26 November 2013 01:54
To: The elegant MVC web framework
Subject: Re: [Catalyst] Setting file handle as the response body generates 
warnings.

We should probably document what it means by $c->response->body can accept a 
file handle.  Like plack specifies the interface it must deal with.  Anyone up 
to that?

This FH in body thing is something I've been thinking about a lot lately, in 
regards to when Catalyst is running under an event loop for example, should 
Catalyst stream the Filehandle a non blocking manner.  But it would be great to 
document this.  Also, I am thinking setting the default size when its missing 
could really belong to middleware.  Plack has some default middleware that does 
this:

https://metacpan.org/source/MIYAGAWA/Plack-1.0030/lib/Plack/Middleware/ContentLength.pm

the means it works looks like this

https://metacpan.org/source/MIYAGAWA/Plack-1.0030/lib/Plack/Util.pm#L68

There's a few things in Catalyst.pm that could profitable just use 
Plack::Middleware counterparts.

just a thought.

johnnap

On Thursday, November 21, 2013 9:20 AM, neil.lunn 
<[email protected]<mailto:[email protected]>> wrote:
On 22/11/2013 12:33 AM, Bill Moseley wrote:


On Wed, Nov 20, 2013 at 11:32 PM, neil.lunn 
<[email protected]<mailto:[email protected]>> wrote:

This approach may work for you is the compressed data is actually in a scalar 
and not too large. And not too small. YMMV.

my $z = read_file "product.json.gz";

my $io = IO::Scalar->new( \$z );
$io->seek( -4, 2 );
$io->read( my $buf, 4);

my $uncompressed_size = unpack( 'V', $buf );


This indeed does work in my tests.   Thanks for all the help, Neil.   I really 
appreciate the time you spent on this.

No prob. Part of my thing on list reponses is that there is a seed for others 
to learn from what was discussed.
I do wonder if there is a sane way to test for an in memory file handle and 
give a more appropriate warning, but that is for further discussion.



--
Bill Moseley
[email protected]<mailto:[email protected]>



_______________________________________________

List: [email protected]<mailto:[email protected]>

Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst

Searchable archive: http://www.mail-archive.com/[email protected]/

Dev site: http://dev.catalyst.perl.org/




________________________________
[http://static.avast.com/emails/avast-mail-stamp.png]<http://www.avast.com/>

This email is free from viruses and malware because avast! 
Antivirus<http://www.avast.com/> protection is active.



_______________________________________________
List: [email protected]<mailto:[email protected]>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
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: Pharos House, 67 High Street, Worthing, West Sussex, BN11 1DN. H L 
Partnership Limited is authorised and regulated by the Financial Conduct 
Authority.
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to