I have a Mason-enabled mod-perl site for which I'm trying to deliver files to certain users. These files are stored as BLOBS in a MySQL db to prevent bookmarking of files on disk. The Mason help-page shows this as a method for accomplishing this with files that *are* on disk:
use Apache::SubRequest;
my $subr = $r->lookup_file($file);
return 404 unless -f $file and $subr->status == 200;
$r->content_type($subr->content_type);
$r->send_http_header;
return 200 if $r->header_only;
$subr->run;
$m->abort;
I would use Apache2, instead, but that's minor. What I can't figure out how to do is make this work using a BLOB object instead of a file on disk. One way would be to override the headers, but the Apache::request and Apache2::request objects are just different enough that I'm not sure how to proceed. Here is one long way around:
$r->content_type('application/octet-stream');
$r->header_out('Content-disposition' => ("attachment; filename=$filen
+ame_base"));
open($fh,"<".$filename_full) or $m->redirect('file_open_failed.html?na
+me='.$filename_full);
while(<$fh>) { $m->print($_); }
close $fh;
return;
This gets me around the BLOB problem, but there's no $r->header_out method in Apache2, and I can't figure out the correct structure use of Apache2::headers_out() from the documentation. I'm sure it's something obvious, but I'm stumped.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.