Hello all, i am a niewbie using-learning -Python-Zope-Plone and i am trying to retrive-show some data from Sql Server 2000. Among those data there is a BLOB image field. Trying to find out how to show this field as image i was reading another older thread titled "How to have a servlet return an image?" dated 05/20/2004. Witch says:
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 ------------------- My problems and questions are: 1) I cannot get to find where cms module is to import ImageComponent 2) What exactly is the id i sould pass and where is the table that contains the BLOB image field passed? thank you in advance ------------------------------------------------------- This SF.Net email is sponsored by the JBoss Inc. Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information _______________________________________________ Webware-discuss mailing list Webware-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/webware-discuss