Re: Sending a file to the browser
Andrew Kirkland <[email protected]> Mon, 6 Oct 2014 11:27:48 +1100
| Newsgroups | gmane.comp.web.mason.user |
|---|---|
| Message-ID | <CAF99VRXasNiDfE0aX-uDWnfOULiaTSgFF=5zFq=4TTVsJrQB2A@mail.gmail.com> |
--===============1251657144355412741==
Content-Type: multipart/alternative; boundary=001a11c123260925ef0504b62745
--001a11c123260925ef0504b62745
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Try this. Just create a dhandler.mp in the folder where the generated
images would be located. You=E2=80=99ll need to change the MIME Type depend=
ing on
the type of image you=E2=80=99re 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 =3D $m->request_args();
# Grab the filename from the path
# ie. /images/generated.jpg returns 'generated.jpg'
my $filename =3D $m->path_info();
# Generate some data
# my $image data =3D ...
# ...
$m->clear_buffer();
$m->res->content_type( 'image/jpeg' );
$m->res->header( 'Content-Disposition' =3D> qq{attachment;
filename=3D"$filename"} );
$m->print( $image_data );
$m->abort();
}
I hope this helps.
=E2=80=8B
On 6 October 2014 10:55, Andrew Kirkland <[email protected]> wrote:
> I recently did this for CSV files. I'll send you the code when I get back
> to the office :)
> On 06/10/2014 10:54 AM, <[email protected]> wrote:
>
>> Dear All,
>>
>> I currently generate an image dynamically and would
>> like to send it from within a component to the client.
>>
>> I found ways to deal with this issue with Html::Mason,
>> (clearing the buffer, setting the content type, etc)
>> but I'd like to achieve this with Mason+Poet.
>>
>> What would be the proper way proceed?
>>
>> Thank you,
>> =3DBO
>>
>>
>> ------------------------------------------------------------------------=
------
>> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
>> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
>> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
>> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=3D154622311&iu=3D/4140/ost=
g.clktrk
>> _______________________________________________
>> Mason-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/mason-users
>>
>
--=20
View Andrew's Linkedin profile <http://au.linkedin.com/in/djandiek>
[image: http://au.linkedin.com/in/djandiek]
<http://au.linkedin.com/in/djandiek>
--001a11c123260925ef0504b62745
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"markdown-here-wrapper" style><p style=3D"mar=
gin:1.2em 0px!important">Try this. Just create a <a href=3D"http://dhandle=
r.mp">dhandler.mp</a> in the folder where the generated images would be loc=
ated. You=E2=80=99ll need to change the MIME Type depending on the type of =
image you=E2=80=99re generating.</p>
<pre style=3D"font-size:0.85em;font-family:Consolas,Inconsolata,Courier,mon=
ospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class=3D"hlj=
s language-perl" style=3D"font-size:0.85em;font-family:Consolas,Inconsolata=
,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap=
;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-ri=
ght-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px=
;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:=
auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-r=
ight-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,=
204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:a=
uto;padding:0.5em;color:black;background:rgb(255,255,255)"><span class=3D"h=
ljs-comment" style=3D"color:rgb(0,106,0)">#################################=
##############################################</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)">#</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Application =
: Your application name</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Filename =
: /images/<a href=3D"http://dhandler.mp">dhandler.mp</a></span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Purpose =
: Generate dynamic file</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Last Author =
: $Author: $</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Last Date =
: $Date: $</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Last Version =
: $Revision: $</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)">#</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)">#################=
##############################################################</span>
<span class=3D"hljs-keyword" style=3D"color:rgb(170,13,145)">use</span> Poe=
t <span class=3D"hljs-string" style=3D"color:rgb(196,26,22)">qw( <span clas=
s=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$log</span> )</span>;
method handle() {
<span class=3D"hljs-keyword" style=3D"color:rgb(170,13,145)">my</span> =
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$arg</span> =
=3D <span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
->request_args();
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Grab the fi=
lename from the path</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># ie. /images=
/generated.jpg returns 'generated.jpg'</span>
<span class=3D"hljs-keyword" style=3D"color:rgb(170,13,145)">my</span> =
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$filename</sp=
an> =3D <span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</s=
pan>->path_info();
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># Generate so=
me data</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># my $image d=
ata =3D ...</span>
<span class=3D"hljs-comment" style=3D"color:rgb(0,106,0)"># ...</span>
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
->clear_buffer();
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
->res->content_type( <span class=3D"hljs-string" style=3D"color:rgb(1=
96,26,22)">'image/jpeg'</span> );
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
->res->header( <span class=3D"hljs-string" style=3D"color:rgb(196,26,=
22)">'Content-Disposition'</span> =3D> <span class=3D"hljs-strin=
g" style=3D"color:rgb(196,26,22)">qq{attachment; filename=3D"<span cla=
ss=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$filename</span>"=
}</span> );
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
-><span class=3D"hljs-keyword" style=3D"color:rgb(170,13,145)">print</sp=
an>( <span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$image_d=
ata</span> );
<span class=3D"hljs-variable" style=3D"color:rgb(63,110,116)">$m</span>=
->abort();
}
</code></pre>
<p style=3D"margin:1.2em 0px!important">I hope this helps.</p>
<div title=3D"MDH:VHJ5IHRoaXMuIEp1c3QgY3JlYXRlIGEgwqA8YSBocmVmPSJodHRwOi8vZ=
GhhbmRsZXIubXAiIHRh
cmdldD0iX2JsYW5rIj5kaGFuZGxlci5tcDwvYT4gaW4gdGhlIGZvbGRlciB3aGVyZSB0aGUgZ2V=
u
ZXJhdGVkIGltYWdlcyB3b3VsZCBiZSBsb2NhdGVkLiBZb3UnbGwgbmVlZCB0byBjaGFuZ2UgdGh=
l
IE1JTUUgVHlwZSBkZXBlbmRpbmcgb24gdGhlIHR5cGUgb2YgaW1hZ2UgeW91J3JlIGdlbmVyYXR=
p
bmcuPGRpdj5gYGBwZXJsPC9kaXY+PGRpdj48ZGl2PiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyM=
j
IyMjIzx3YnI+IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjPHdicj4jIyMjIyMjIyMjIyM=
j
IyMjIyMjPC9kaXY+PGRpdj4jPC9kaXY+PGRpdj4jICZuYnNwOyBBcHBsaWNhdGlvbiAmbmJzcDs=
g
Jm5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014 10:55, Andrew Kirkland <span dir=3D"ltr"><<a href=3D"mailto:djandiek=
@gmail.com" target=3D"_blank">[email protected]</a>></span> wrote:<br><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
#ccc solid;padding-left:1ex"><p dir=3D"ltr">I recently did this for CSV fi=
les. I'll send you the code when I get back to the office :) </p><div c=
lass=3D"HOEnZb"><div class=3D"h5">
<div class=3D"gmail_quote">On 06/10/2014 10:54 AM, <<a href=3D"mailto:b=
[email protected]" target=3D"_blank">[email protected]</a>> wrote:<br type=3D=
"attribution"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">Dear All,<br>
<br>
I currently generate an image dynamically and would<br>
like to send it from within a component to the client.<br>
<br>
I found ways to deal with this issue with Html::Mason,<br>
(clearing the buffer, setting the content type, etc)<br>
but I'd like to achieve this with Mason+Poet.<br>
<br>
What would be the proper way proceed?<br>
<br>
Thank you,<br>
=3DBO<br>
<br>
---------------------------------------------------------------------------=
---<br>
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer<br>
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports<br=
>
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper<br>
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer<br>
<a href=3D"http://pubads.g.doubleclick.net/gampad/clk?id=3D154622311&iu=
=3D/4140/ostg.clktrk" target=3D"_blank">http://pubads.g.doubleclick.net/gam=
pad/clk?id=3D154622311&iu=3D/4140/ostg.clktrk</a><br>
_______________________________________________<br>
Mason-users mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Maso=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/mason-users" target=
=3D"_blank">https://lists.sourceforge.net/lists/listinfo/mason-users</a><br=
>
</blockquote></div>
</div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>=
<div dir=3D"ltr"><div style=3D"text-align:center"><br></div><div style=3D"t=
ext-align:center"><a href=3D"http://au.linkedin.com/in/djandiek" target=3D"=
_blank">View Andrew's Linkedin profile</a></div><div style=3D"text-alig=
n:center"><a href=3D"http://au.linkedin.com/in/djandiek" target=3D"_blank">=
<img src=3D"http://s.c.lnkd.licdn.com/scds/common/u/img/webpromo/btn_liprof=
ile_blue_80x15.png" alt=3D"http://au.linkedin.com/in/djandiek"></a></div></=
div>
</div>
--001a11c123260925ef0504b62745--
--===============1251657144355412741==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Slashdot TV. Videos for Nerds. Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
--===============1251657144355412741==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users
--===============1251657144355412741==--