[cgiapp] How to send pdf file?
Jesse Erlbaum
jesse at erlbaum.net
Sun Feb 3 08:34:00 EST 2008
Hi Petr --
> MIME headers are correct, but I still don't know how to send binary
> output through CGI::Application.
> On "classic" way it is easy:
> open(FILE, "<test.pdf");
> @fileholder = <FILE>;
> close (FILE);
>
> print "Content-Type: application/pdf\n";
> print "Content-Disposition: attachment;filename=test.pdf\n\n";
> print @fileholder;
>
>
> How to do it through CGI::Application?
It's basically the same w/ CGI::Application, with two exceptions:
1. You don't return the headers. You set them.
2. You don't print -- you return your data.
sub send_pdf {
my $self = shift;
$self->header_props( -type => "application/pdf",
-"Content-Disposition"=>"attachment;filename=test.pdf"
);
open(FILE, "<test.pdf");
@fileholder = <FILE>;
close (FILE);
return join("", @fileholder);
}
TTYL,
-Jesse-
Jesse Erlbaum
The Erlbaum Group, LLC
817 Broadway, 10th floor
New York, NY 10003
212-684-6161 (office)
917-647-3059 (mobile)
212-684-6226 (fax)
jesse at erlbaum.net
More information about the cgiapp
mailing list