1.11M Members

store image in blob type of mysql

 
0
 

Hi all,

i am new to python
how to store image into database blob using python
please help me for this its urgent

 
1
 

Hi,

first of all storing a BLOB is very bad design.

But, it would be like this:

blob_value = open('image.jpg', 'rb').read()
sql = 'INSERT INTO Tab1(blob_field) VALUES(%s)'
args = (blob_value, )

cursor.execute (sql, args)
connection.commit()
 
0
 

Hi,

first of all storing a BLOB is very bad design.

But, it would be like this:

blob_value = open('image.jpg', 'rb').read()
sql = 'INSERT INTO Tab1(blob_field) VALUES(%s)'
args = (blob_value, )

cursor.execute (sql, args)
connection.commit()

Thanks yar your code is working fine.

 
0
 

thanks yar your code is working fine

 
0
 

can you help me how to retrieve the image back

 
0
 

I would try

sql = 'SELECT `blob_field` FROM `Tab1`'
cursor.execute(sql)
for row in cursor:
    blob_value = row[0]
You
Post:
Start New Discussion
Tags Related to this Article