String Literal to Blob

Victor Subervi victorsubervi at gmail.com
Wed Apr 9 20:29:21 CEST 2008


On Wed, Apr 9, 2008 at 1:49 PM, Steve Holden <steve at holdenweb.com> wrote:

> Victor Subervi wrote:
> > On Wed, Apr 9, 2008 at 12:51 PM, Steve Holden <steve at holdenweb.com
> > <mailto:steve at holdenweb.com>> wrote:
> I imagine the following code should do so, given your earlier writings:
>
> #! /usr/bin/python
>
> import MySQLdb
>
> print "Content-type: image/jpeg\r\n"
> host = 'host'
> db = 'bre'
> user = 'user'
> passwd = 'pass'
> connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> cursor = connection.cursor()
> cursor.execute('select img from photo where id="7";')
> content = cursor.fetchall()[0][0]
> f = open("somefile.jpg", "w")
> f.write(content)
> f.close()
>
> Then see if you can deal with "somefile.jpg" like any other JPEG. If you
> can't then your blobs are somehow being mangled. If you can, we'll take
> it from there.


Yes, I can. Shows up in browser when surfed to, and it was pulled from the
database. No mangling. I am signing off, back tomorrow morning.
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080409/077a8623/attachment.html>


More information about the Python-list mailing list