Hi Andrew,
thanks for your help. Actually, I did not want to trigger a download,
but rather just serve an image generated dynamically.
One way to solve the original problem that worked for me was writing
down a file to a public location and redirecting the client to that
location.
You however answered my question: printing through $m->print as you
suggested did the trick. I was attempting:
my $bin = File::Slurp::read_file( $file, binmode => ':raw' ) ;
$m->res->body( $bin );
but this resulted in a corrupted image on the client side. (Why?)
Thank you very much,
=BO
PS: Why is it that there is no need for
CLASS->no_wrap;
in the file?
PPS: In HTML::Mason, $r->sendfile was available;
Is there any direct equivalent?
On Mon, 6 Oct 2014 11:27:48 +1100
Andrew Kirkland <[email protected]> wrote:
> Try this. Just create a dhandler.mp in the folder where the generated
> images would be located. You’ll need to change the MIME Type
> depending on the type of image you’re generating.
>
> #################################################################################
> Application : Your application name# Filename :
> /images/dhandler.mp# Purpose : Generate dynamic file# Last
> Author : $Author: $# Last Date : $Date: $# Last Version
> : $Revision:
> $################################################################################
> use Poet qw( $log );
>
> method handle() {
> my $arg = $m->request_args();
>
> # Grab the filename from the path
> # ie. /images/generated.jpg returns 'generated.jpg'
> my $filename = $m->path_info();
>
> # Generate some data
> # my $image data = ...
> # ...
>
> $m->clear_buffer();
> $m->res->content_type( 'image/jpeg' );
> $m->res->header( 'Content-Disposition' => qq{attachment;
> filename="$filename"} );
> $m->print( $image_data );
> $m->abort();
> }
>
> I hope this helps.
------------------------------------------------------------------------------
Slashdot TV. Videos for Nerds. Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users