[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] How to download a dynamically generated file


> You had asked for a way to send the PDF a few pieces at a time to
> avoid having the entire file in memory at once.  Setting
> '$ENV{CGI_APP_RETURN_ONLY}', in combination with passing 'none' into
> header_type(), does exactly that :-)

Eric, I think you're confusing me with Steve Hay, who originally asked the
question ;)

> I was just saying that I hope that there might some day be a less cryptic
> way of going about that.  Perhaps it would work today by returning a hash
> from the run_mode, instead of a string.  Then, we could have an overloaded
> stringify operation call a custom output procedure when CGI::App calls
> "print $output" at the end of the run() method.  That output procedure
> would then read a file in, line by line, and avoid the overhead of
> slurping it in during the run_mode.  However, some might suggest that
> doesn't really make it any less cryptic ;-)

Setting $self->header_type('none'); followed by printing the headers
yourself and then opening a file in the run-mode and printing it line by
line and finally followed by return ''; *should* hypothetically solve the
problem without relying on undocumented CGIApp features.

Basically if you return the headers yourself in the run-mode and set the
header type to 'none' then when you return nothing to CGIApp it will append
nothing to what you've already printed out.

A fairly un-elegant solution but then again it's a fairly irregular
scenario. I'd imagine that if it's something an application will be doing
regularly, a function in the superclass like:

sub return_file_contents
{
    my $self      = shift;
    my $file       = shift;
    my $name   = shift;

    # tell CGIApp not to set headers of it's own
    $self->header_type('none');

    # print our own headers
    print "Content-Type: application/octetstream\n";
    print "Content-Disposition: attachment; filename=$name\n\n";

    # or whatever other method of read / return line by line that may be
faster
    open FILE, $file;
    print $_ while( <FILE> );
    close FILE;

    # delete the file
    unlink ( $file );

    # return nothing to CGIApp
    return '';
}

and could then be called at the bottom of the run-mode returning the file
as:

return $self->return_file_contents( '/usr/home/files/information.pdf',
'Product Information.pdf' );

It's *a* solution, maybe not the best one, but technically one that 'should'
work .. ;)


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.