Display raw image - given byte[]?

5 messages Options
Embed this post
Permalink
Mathew Rowley-2

Display raw image - given byte[]?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Display raw image - given byte[]? 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.

MAT

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Daniel Dekany

Re: Display raw image - given byte[]?

Reply Threaded More More options
Print post
Permalink
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


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Mathew Rowley-2

Re: Display raw image - given byte[]?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Re: [FreeMarker-user] Display raw image - given byte[]? 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? Are there any other issues with doing as the tutorial describes?  Thanks.

MAT


On 10/13/09 2:44 PM, "Daniel Dekany" <ddekany@...> 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



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Attila Szegedi-3

Re: Display raw image - given byte[]?

Reply Threaded More More options
Print post
Permalink
As long as the template doesn't write anything else on its own into  
the response writer ('cause it'll use the writer, not output stream),  
I think it would work. I can hardly recommend you do this though - it  
seems highly abusive; you're reaching from a higher level of  
abstraction (view-generating template) to a lower level of abstraction  
(servlet API). If I were you, I'd have a separate Java servlet that  
returns the images, and direct image requests to its URL.

Attila.

--
home: http://www.szegedi.org
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com

On 2009.10.14., at 2:10, 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? Are there any  
> other issues with doing as the tutorial describes?  Thanks.
>
> MAT
>
>
> On 10/13/09 2:44 PM, "Daniel Dekany" <[hidden email]> 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

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Daniel Dekany

Re: Display raw image - given byte[]?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mathew Rowley-2
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" <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user