Retrieving and displaying images on the fly

11 views
Skip to first unread message

Voltron

unread,
Dec 6, 2009, 4:10:14 AM12/6/09
to cherrypy-users
I have an object called "user" which I am passing to my Jinja2
template. This object contains the user_name avatar image and other
properities

user['user_name']
user[avatar_image']
...

All other values work except the image file, I suspect its because I
might have to send the header for the image file as in:

cherrypy.response.headers['Content-Type'] = "image/png"

My question is, how can I achieve this? I cannot just change the
header to image/png because I am rendering the whole template with
other values with html/xml headers.

Thanks

Alex

unread,
Dec 6, 2009, 7:45:46 AM12/6/09
to cherrypy-users


On Dec 6, 10:10 am, Voltron <nhy...@googlemail.com> wrote:
> I have an object called "user" which I am passing to my Jinja2
> template. This object contains the user_name avatar image and other
> properities
>
> user['user_name']
> user[avatar_image']
> ...
>
> All other values work except the image file, I suspect its because I
> might have to send the header for the image file as in:
>
> cherrypy.response.headers['Content-Type'] = "image/png"
>
> My question is, how can I achieve this?

I think you can't. You should pass the URL of the image in your object
and not the binary image.

Hope this helps.

Alex

Paweł Stradomski

unread,
Dec 6, 2009, 2:57:42 PM12/6/09
to cherryp...@googlegroups.com
W liście Alex z dnia niedziela 06 grudnia 2009:
At least that's the most standard way, which works in all browsers. But if
original poster really needs to embed the image in the page, he can use data:
urls (not supported by IE) and MHTML (supported only by IE)
--
Paweł Stradomski

Voltron

unread,
Dec 8, 2009, 5:24:57 PM12/8/09
to cherrypy-users
Thanks guys!
Reply all
Reply to author
Forward
0 new messages