This is my first question.
I have users who upload their own image to the database. This image is stored as a BLOB.
I was able to do this successfully. I use MySQL for the database.
In the part with which I am having problems, this BLOB is displayed as an image on the website when it is called.
Now only binary data is displayed, a lot of strange characters. I think this is a problem with the HTTP header. Now it is in:
print "Content-Type: text/html"
I tried:
print "Content-Type: image/jpeg"
I use Python to connect to a database and write HTML.
Edit: Code:
def showFile(): # do SQL to retrieve blob where filename conn, cursor = getConnectionAndCursor() sql = """ select data from upload where id=1 """ cursor.execute(sql) data = cursor.fetchone() blob = data[0] print "<hr>" print "This is what I'm trying" print """<img src="data:image/jpeg;base64,%s/>""" % data ###################################################################### if __name__ == "__main__": form = cgi.FieldStorage() if "show_file" in form: print "Content-Type: text/html" print printHeaders("Image upload example") showFile() printFooter()
source share