putting Image from database in cgi app
vivek kumar
gupt_vive at hotmail.com
Wed May 21 08:27:12 EDT 2003
>From: Gerhard Häring <gh at ghaering.de>
>To: python-list at python.org
>Subject: Re: putting Image from database in cgi app
>Date: Wed, 21 May 2003 13:14:39 +0200
>
>vivek kumar wrote:
>> I was wondering if there is any way to show the file read from database
>>in the cgi app..
...
>>like: cur.execute("select pic from pictest where id=1")
>> rst=cur.fetchone()
>> s=open("temp.jpg","wb")
>> s.write(rst[0])
>> s.close
>> print '<img src="temp.jpg">'
>>
>>So, I was wondering if there is any way in which I can show the file
>>directly without creating an intermediate file???
>Sure, but one HTTP request can only deliver one resource to the client, be
>it a HTML document or a JPEG image.
>
>A CGI script that would deliver a JPEG image to the client could look like
>this:
>
>#v+
>...
>cu = cx.cursor()
>cu.execute("SELECT PIC FROM PICTEST WHERE ID=1")
>img = cu.fetchone()[0]
>
>print "Content-type: image/jpeg\n"
>print img
>
>cx.close()
>#v+
>
>-- Gerhard
THX a lot for that. But what I want to do is to show the image with some
related data. I am working on a shopping cart typo thing (Book Store) and I
want to show the image with various details like book name,author etc with
the Image (like an IMG tag in a HTML document). Is it possible to do it
without creating a temporary file??
TIA and Kind Regards
Vivek Kumar
_________________________________________________________________
Calling NRIs! Manage your money smartly.
http://server1.msn.co.in/msnspecials/nriservices/index.asp Click here for
more.
More information about the Python-list
mailing list