Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: File download from BLOB

by Anonymous Monk
on Mar 28, 2011 at 03:34 UTC ( [id://895828]=note: print w/replies, xml ) Need Help??


in reply to File download from BLOB

I bet you're forgetting to discard anything already in Mason's output buffer before sending the binary.

$m->clear_buffer;

You must also make sure you stop producing more output after you send the binary file.

$m->abort;

Replies are listed 'Best First'.
Re^2: File download from BLOB
by wolfie7873 (Novice) on Mar 28, 2011 at 13:54 UTC

    I bet you're forgetting to discard anything already in Mason's output buffer before sending the binary.

    I'll bet you're spot on. I changed my test file from a pdf to an excel spreadsheet. When it tries to open it tells me there are missing files, all of which are .css pages loaded by the autohandler.

    I used the $m->clear_buffer method, and Excel no longer complains about missing files, but the content of the spreadsheet is the content from the autohandler that occurs after the $m->call_next() call. Is there anyway around that?

    There is no 'content' in the called component, and this is the (current) entirety of the <%init> block.

    <%init> $filename = 'fairtax.xls'; use Apache2::SubRequest; my $file = '/var/www/eddie/fairtax.xls'; my $subr = $r->lookup_file($file); return 404 unless -f $file and $subr->status == 200; $m->clear_buffer; $r->err_headers_out->add('Content-disposition' => ("attachment; filena +me=$filename")); $r->content_type($subr->content_type); $r->send_http_header; return 200 if $r->header_only; $subr->run; $m->abort; </%init>
      Finally got it to work - here's how. Thank you to everyone who helped:
      $r->content_type('application/x-download'); $r->err_headers_out->add('Content-disposition' => ("attachment; filena +me=$filename")); my ($st,$sth) = (); $st = "SELECT bin_data FROM forms WHERE filename = '$filename'"; $sth = $dbh->prepare($st) or die "Prepare Failed! " . $st . $dbh->errs +tr(); $sth->execute() or die "Execute Failed! " . $st . $sth->errstr(); my $filedata = $sth->fetchrow(); $sth->finish(); $m->clear_buffer; $m->print( $filedata ); $m->abort; return;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://895828]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found