Displaying images stored as binary in MySQL

Blaktyger blaktyger at hotmail.com
Sat Aug 14 02:26:58 CEST 2004

Benjamin Niemann <b.niemann at betternet.de> wrote in message news:<cfifm8$3bn$1 at online.de>...
> Blaktyger wrote:
> > How can this be done? Images are stored in a LONGBLOB field. When I
> > try to display them, it prints out the binary data as it is...
> Display where? On local screen, in a webbrowser?
> Assuming the first one, see post by Tom.
> Assuming the second one (you're writing a cgi,mod_python... program), 
> did you set the content-type in the http header correctly?
In a webbrowser...
this is my code...


print 'Content-Type:image/jpeg\n\n'
import blakHtml, sys
sys.stderr = sys.stdout
import MySQLdb
import urllib
import cgi
import time
newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \
                                           passwd='linux4ever', db='photoFamille')

sqlCmdFr="""SELECT *  FROM photo"""
resultats = curseur.fetchall()
for val in resultats:
    #print '<img src=" ' + val[5]+ ' " ' +' >' THIS DOES NOT WORK
    print val[5]
I know there is no HTML code but this is just a test...

More information about the Python-list mailing list