String Literal to Blob
victorsubervi at gmail.com
Tue Apr 8 18:55:07 CEST 2008
Thanks. I apparently am printing some holder for the image. I stripped out
most of it with this
but then I am left with this:
How do I extract an image from that?
On Tue, Apr 8, 2008 at 11:15 AM, Steve Holden <steve at holdenweb.com> wrote:
> Victor Subervi wrote:
> > Hi:
> > I am able (finally) to upload an image to the database. However, when I
> > try to retrieve it, I get a string literal. Here is my code:
> > #!/usr/local/bin/python
> > import cgitb; cgitb.enable()
> > import MySQLdb
> > def test():
> > host = 'mysqldb2.ehost-services.com <
> > user = 'user'
> > passwd = 'pass'
> > db = 'bre'
> > db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> > cursor= db.cursor()
> > cursor.execute('select pic1 from products where id="3";')
> > content = cursor.fetchall()
> > # print 'Content-Type: image/jpeg\r\nContent-Length: %d\n' %
> > print 'Content-Type: image/jpeg\r\n'
> > print '<html><body>\n'
> > print content
> > print '</body><html>\n'
> > cursor.close()
> > test()
> > (Apparently, Plesk doesn´t like if __name__ == '__main__': )
> > The commented out line gives me a leading less than sign...and that´s
> > it. What do?
> > TIA,
> > Victor
> Your headers indicate you intend to serve a JPEG image, so you should
> *not* then include HTML. Take a look at the HTML of a web page with an
> image inside it (look for the <IMG src="..."> tag) and you will see that
> HTML pages reference images as separate web resources.
> Thus once you have printed out your HTML headers you should them
> immediately send the contents of the database column.
> Steve Holden +1 571 484 6266 +1 800 494 3119
> Holden Web LLC http://www.holdenweb.com/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list