title: Converting BLOB, stored on a database, to an image on an HTML website
body: <p>This is my first question.</p>
  
  <p>I am having users upload their own image to a database.
  That image is stored as a BLOB.</p>
  
  <p>I was able to do this successfully. 
  I am using MySQL for the database.</p>
  
  <p>The part I am having trouble with is displaying that BLOB as an image on the website when its called upon.</p>
  
  <p>Right now only the Binary data, lots of weird symbols are being displayed. I think its a problem with the HTTP header. Right now its in :</p>
  
  <pre><code>print "Content-Type: text/html"
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>print "Content-Type: image/jpeg"
  </code></pre>
  
  <p>I am using Python to connect with the database and write the HTML. </p>
  
  <p>Edit: Code:</p>
  
  <pre><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 "&lt;hr&gt;"
      print "This is what I'm trying"
      print """&lt;img  src="data:image/jpeg;base64,%s/&gt;""" % data
  
  ######################################################################
  if __name__ == "__main__":
  
      form = cgi.FieldStorage()
  
      if "show_file" in form:
          print "Content-Type: text/html"
          print 
          printHeaders("Image upload example")
          showFile()
          printFooter()
  </code></pre>