1,105,585 Community Members

store image in blob type of mysql

Member Avatar
rajeshwari_ib
Newbie Poster
8 posts since Dec 2009
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all,

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

Member Avatar
programmersbook
Junior Poster
121 posts since Nov 2009
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 0 [?]
 
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()
Member Avatar
rajeshwari_ib
Newbie Poster
8 posts since Dec 2009
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
rajeshwari_ib
Newbie Poster
8 posts since Dec 2009
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks yar your code is working fine

Member Avatar
kilaru.abhinav
Newbie Poster
1 post since Mar 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

can you help me how to retrieve the image back

Member Avatar
Gribouillis
Posting Maven
3,457 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 884 [?]
Skill Endorsements: 18 [?]
Moderator
 
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