Re: Display raw image - given byte[]?

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, October 14, 2009, 2:10:14 AM, Mathew Rowley wrote:

> I came across this tutorial:
>
> http://www.conandalton.net/2008/10/sending-binary-data-from-freemarker.html
>
> It uses freemarker to call a method that writes to the default
> stream.  Is there any security ramification to have the template
> being able to access the HttpServletRespones object?

Nope... we left it to the frameworks/application developer to decide
what and how how it makes accessible for the templates, and many
indeed exposes the HttpServletRespone.

> Are there any other issues with doing as the tutorial describes?

I would say, if you have to do this, your Web application framework
has a problem, or your Servlet setup has... It's a very very dirty
hack. It doesn't use FreeMarker to output anything, it just uses it as
a script language that can call Java methods and so can do anything.
An a such method grabs the output stream and dumps directly into it,
totally bypassing FreeMarker... Thus, you have to be very careful so
that FreeMarker itself doesn't print anything, not even an empty line,
because that will inserted somewhere into the binary, hence corrupting
it.

> Thanks.
>
> MAT
>
>
> On 10/13/09 2:44 PM, "Daniel Dekany" <[email protected]> wrote:
>
> Tuesday, October 13, 2009, 9:29:47 PM, Mathew Rowley wrote:
>
>> I have an interface that returns an image in the form ‘byte[]’.  Is
>> it possible to create a ftl that “writes” that image out to the user
>> – setting the header to image/png, etc?  Thanks.
>
> Nope... FreeMarker has no control over the MIME-type or over the
> output charset (which should be ISO-8859-1 if you want to keep the
> bits); the embedding framework has. Even then, it would be quite
> inefficient due to FreeMarker uses 16 bit char-s (UNICODE) internally.
> Last not least, it would be a miss-use of FreeMarker.
>
>> MAT
> --
> Best regards,
>  Daniel Dekany
>
>

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.