String Literal to Blob

Victor Subervi victorsubervi at gmail.com
Tue Apr 8 12:55:07 EDT 2008


Thanks. I apparently am printing some holder for the image. I stripped out
most of it with this
content[0][0]
but then I am left with this:

array('c', '\xff\xd8\xff\xe0\\0\x10JFI...)
How do I extract an image from that?

TIA,

Victor



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 <
> http://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' %
> len(content)
> >   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.
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080408/8ca885ab/attachment.html>


More information about the Python-list mailing list