Sebastien Lemieux wrote:
Hi fellow webwarer,
I'm wondering if Webware can be adapted to return an image (png for
instance) instead of a HTML page. I've used that trick through .cgi in
the past to have dynamically generated images (most of these .cgi were
coded in C).
i've done a similar thing in the past, the code below just extract the image from a mysql table (using an id passed as querystring) and send to the browser. the use is trivial:
<im src="/path/to/image?id=666" width="300" height="200">
you may want to output some cache info to the browser too, otherwise the browser will keep asking for the same image even if it's not really needed.
hope this helps.
# ------------------ begin ------------------
from WebKit.HTTPServlet import HTTPServlet from WebKit.Application import EndResponse
import db from cms import ImageComponent cm = db.ConnectionManager()
class image(HTTPServlet): """ Fetch an image resource given its id and send to browser. """
def respondToGet(self, transaction):
request = transaction.request() response = transaction.response()
id = request.field('id', '').strip() if not id.isdigit(): # set '400 Bad request' HTTP response response.sendError(400, 'Bad request') raise EndResponse
# get resource from DB
row = db.row(cm.connection, ImageComponent._table, ImageComponent._pk, int(id))
# set '200 OK' HTTP response response.setStatus(200, 'OK')
data = row['data']
response.setHeader('Content-Type', '%s' % row['mime_type']) response.setHeader('Content-Length', '%d' % len(data)) response.write(data)
response.flush()
# ------------------ end -------------------
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss