473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Displaying images stored as binary in MySQL

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...

Thank you
Jul 18 '05 #1
5 5009

"Blaktyger" <bl*******@hotmail.com> wrote in message
news:c9**************************@posting.google.c om...
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...

Thank you

You could get PIL at http://www.pythonware.com/products/pil/

and try the Image.fromstring() function.

Tom
Jul 18 '05 #2
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?
Jul 18 '05 #3
Benjamin Niemann <b.*******@betternet.de> wrote in message news:<cf**********@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...

#!/usr/bin/python2.3

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

sqlCmdFr="""SELECT * FROM photo"""
curseur.execute(sqlCmdFr)
resultats = curseur.fetchall()
p=0
for val in resultats:
p=p+1
#print '<img src=" ' + val[5]+ ' " ' +' >' THIS DOES NOT WORK
print val[5]
newConnection.close()
I know there is no HTML code but this is just a test...
Jul 18 '05 #4
>>>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...

#!/usr/bin/python2.3

print 'Content-Type:image/jpeg\n\n'

You must use '\r\n' to terminate header lines. I'm not really sure, but
maybe there should also be a spacing between ':' and 'image/jpeg'...
If you are using e.g. FireFox as a browser, you can user 'View Page
Info' to see, if the browser correctly understands, what you are trying
to tell it ('Type' should say 'image/jpeg').
import blakHtml, sys
sys.stderr = sys.stdout
import MySQLdb
import urllib
import cgi
import time
prevPg=blakHtml.HTMLDocument()
newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \
passwd='linux4ever', db='photoFamille')
curseur=newConnection.cursor()

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

val[5] contains the raw image data (not a path), correct? Does 'photo'
contains more than one image? Concatenating several images into one
bytestream, is definitly not what you want.

Jul 18 '05 #5
Benjamin Niemann <b.*******@betternet.de> wrote in message news:<cf**********@online.de>...
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...

#!/usr/bin/python2.3

print 'Content-Type:image/jpeg\n\n'

You must use '\r\n' to terminate header lines. I'm not really sure, but
maybe there should also be a spacing between ':' and 'image/jpeg'...
If you are using e.g. FireFox as a browser, you can user 'View Page
Info' to see, if the browser correctly understands, what you are trying
to tell it ('Type' should say 'image/jpeg').
import blakHtml, sys
sys.stderr = sys.stdout
import MySQLdb
import urllib
import cgi
import time
prevPg=blakHtml.HTMLDocument()
newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \
passwd='****', db='photoFamille')
curseur=newConnection.cursor()

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

val[5] contains the raw image data (not a path), correct? Does 'photo'
contains more than one image? Concatenating several images into one
bytestream, is definitly not what you want.


val[5] contains only one image but I saw that when printing out val[5]
is that the binary data is in a array. So this i what I did...

import array
[same code as before except for this... ]

print 'Content-Type: image/jpeg\r\n'
[...]
for val in resultats:
p=p+1
img=''
t=''
# t is an array object. the tostring() argument extracts the
binary data
t=val[5].tostring()
print t
and it works!
Thanks for your help Ben!
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Srdjan Pejic | last post by:
Hello, I have a problem that I have not been able to solve, even after searching the web. I have stored couple of images in the MySQL database and I am trying to get them displayed on a web page...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
7
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application....
0
by: Matt | last post by:
Hi I'm have difficulty displaying images that are stored in a MySQL database. I've tried using the odbc.net provider, the ByteFX provider and the MySQLDriverCS one but can't seem to get the...
7
by: Jim | last post by:
I am trying to display images that are stored in a database, and I am using a repeater control. What I still use the Response.BinaryWrite method with a binding expression, if so, what with the...
3
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
1
by: CodedSammy | last post by:
Hello. I am developing a solution in Visual Basic which will require me to display images stored in a disk files along with the content of my MySQL Database using the filenames of the images to...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.