Fetch images from DB

1 view
Skip to first unread message

Mauro Ciancio

unread,
Dec 30, 2009, 4:53:20 PM12/30/09
to turbo...@googlegroups.com
Hello everyone,

In the app that I've developed with tg2.0 I fetch images from a db. This is my
controller:

@expose(content_type="image/jpeg")
def picture(self, id):
return search_picture(id)

This works pretty well but the stored images are a bit heavy (around ~200kb)
and takes to the browser valuable seconds to load. I'm in the same situation
as in my previous post:

(http://groups.google.com/group/turbogears/browse_thread/thread/a39ece38c77e5429/a34e72eacc29e74b#a34e72eacc29e74b)

I'd like that the pictures were loaded only once and then cached by the browser.
Any ideas?

I've thought about inserting the http headers from my controller (calling to
pylons.request.headers & .response), but I'd have to implement the mechanism
and I don't want to reinvent the weel.

Cheers,
Happy new year =) !
--
Mauro Ciancio <maurociancio at gmail dot com>

Jose Galvez

unread,
Dec 30, 2009, 5:33:34 PM12/30/09
to turbo...@googlegroups.com
reading over your link it looks like you have a partial solution, at
least as indicated by Diez, could you provide a link to that as well so
that we don't have to go looking for it?

Mauro Ciancio

unread,
Dec 30, 2009, 8:30:40 PM12/30/09
to turbo...@googlegroups.com
Jose:

On Wed, Dec 30, 2009 at 7:33 PM, Jose Galvez <jj.g...@gmail.com> wrote:
> reading over your link it looks like you have a partial solution, at
> least as indicated by Diez, could you provide a link to that as well so
> that we don't have to go looking for it?

Sure, here is the tw's thread:

http://groups.google.com/group/toscawidgets-discuss/browse_thread/thread/28d10531a3e00869

In that thread I was looking for a solution to serve statically
tw's css & js files. The solution provided by Diez is great, but
that doesn't applies to this problem because the images are fetched
from a db (and not from the filesystem).

Any ideas?
Thanks again.

Diez B. Roggisch

unread,
Dec 31, 2009, 1:14:50 PM12/31/09
to turbo...@googlegroups.com
Mauro Ciancio schrieb:

> Hello everyone,
>
> In the app that I've developed with tg2.0 I fetch images from a db. This is my
> controller:
>
> @expose(content_type="image/jpeg")
> def picture(self, id):
> return search_picture(id)
>
> This works pretty well but the stored images are a bit heavy (around ~200kb)
> and takes to the browser valuable seconds to load. I'm in the same situation
> as in my previous post:

You need to render, compare and react an ETag field, and use that to
either deliver the image, or return a response with status code 304.

Diez

Mauro Ciancio

unread,
Dec 31, 2009, 5:32:59 PM12/31/09
to turbo...@googlegroups.com
Diez:

On Thu, Dec 31, 2009 at 3:14 PM, Diez B. Roggisch <de...@web.de> wrote:
> You need to render, compare and react an ETag field, and use that to
> either deliver the image, or return a response with status code 304.

Ok, that was I thought.
Thanks again Diez.

Cheers!

Mauro Ciancio

unread,
Dec 31, 2009, 6:11:06 PM12/31/09
to turbo...@googlegroups.com
Well, I've found a solution. I thought it would be harder to implement.
In this page explains about etag_cache, a function that does all the
magic.

http://turbogears.org/2.1/docs/main/Caching.html

Thanks to all.
Cheers.

Reply all
Reply to author
Forward
0 new messages