[cgiapp] How to send pdf file?

petr.vojkovsky at centrum.cz petr.vojkovsky at centrum.cz
Fri Feb 1 10:41:25 EST 2008


Hi,
I want send to browser pdf file (it exist):
I try do it in this rm:

use MIME::Base64;
...
--------------------------------
      my $self = shift;
	my $q = $self->query();
	my $session = undef();
	my $message = '';
	my $output = '';
	my $buf;
	my $files_location = 'PATH TO DIR'; 
	my $filename = 'exam1.pdf';
	open(FILE, "<$files_location/exam1.pdf") or die "$!";
	#binmode FILE;
	my @fs = stat(FILE);
	#my $file_size = $theFileStat->size;
	#my $file_size = $fs[7];
	while (read(FILE, $buf, 60*57)) {
		$output = $output . encode_base64($buf);
	}
	close (FILE); 
	$self->header_props(
		-type    => "application/pdf",
        	-attachment    => $filename,
		-Content_Length     => length($output),
        	-Content_Transfer_Encoding  => "base64",
    );
	$self->header_type('header');
	return $output;
---------------------------

Browser shows "Save as" window, but xpdf can't dislpay it. Why the browser automatically decode_base64 this file?
How to send binary file (*.pdf, *.jpg, ...) without Base64 encoding?


Thank you for advice.
Best regards,
Petr  



More information about the cgiapp mailing list