Serving images directly from database
Even though storing images in the database have its advantages/disadvantages, here is a small guide for those who want to store them in the database and serve them directly to the browser without having to generate a file first. This examples is based on the amazing web framework pylons.
In this example I want to serve small product images from my product controller.
In the product.py controller I have this method
def show_image(self, id, name): response.headers['Content-type'] = 'image/png' response.headers['Cache-Control'] = 'max-age=14400' response.headers['Pragma'] = '' product = Product.get_by(id=id) return product.image
Then in my mako template I have
<img src="url(controller='product', action='show_image', id='${c.product.id}', name='c.product.image_name')"/>which will generate
<img src="/product/show_image/1/super-glue.png"/>So whats happening is that when the page is loading the image tag, the show_image() function is called which fetches the image data from the database and returns the image data buffer to the template. The key for this to work is to set the appropriate headers so that the page know that the data returned is image/png through the Content-type. The name argument is just used to set a name for the image file on the connecting client so that the cached file will have a correct name.

More on Content-type and MIME headers can be found here: http://www.iana.org/assignments/media-types/
Very lucrative…
[...]we like to hye5 “:)” other sites on the web, even sometimes aren’t related to us, by linking to them. check some of them[...]…
heavy duty diesel generators…
[...]the time to read or visit the content or sites we have linked to below the[...]…
Baby Bedding…
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
Potenzmittel Apcalis…
[...]Apcalis SX Oral Jelly Potenzmittel ist im Gegensatz zu anderen Mitteln fluessig einzunehmen[...]…
free grant money for bills…
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]…
Buy Facebook Fans…
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]…
Scrapebox List…
[...]Scrapebox Auto Approve List[...]…
Steve’s Super Site…
[...] You may leave a response, or trackback from your personal site. Read a lot more from the original source: How to Get Ripped: « Ripped Abs weblog Share and [...]…
Yahoo news…
[...] listed below there are plenty of the actual hyperlink towards a sites in which believe you really need to stop by [...] …
Sources…
[...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]……