In here we will see how to connect to db and then get the file (image(blob) / text / xml, etc....) and then save them to local machine ..
From my previous posts you all know how to connect to DB and how to handle basic file operations.
Now by combining both operations we will retrieve the files from db and we will save them.
import cx_Oracle
db = cx_Oracle.connect('USER/PASSWORD@IP.address.machine:port_number/SID')
cursor = db.cursor()
cursor.execute("select image from table_name where value='xyz'")
row = cursor.fetchone()
dbimagefile=row[0]
blob= dbimagefile.read()
imageFile = open("image.jpg",'wb')
#write the data to the file
imageFile.write(blob)
imageFile.close()
cursor.close()
db.close()
In this example i'm saving jpg image from db to local machine..
if your file extension is different then change the extension and then every thing is same...
some of the extensions are like :
wsq
jp2
jpg
gif
doc
xml
json
If you still got any Q's for me feel free to comment will be happy to respond ..
Thanks your support...
From my previous posts you all know how to connect to DB and how to handle basic file operations.
Now by combining both operations we will retrieve the files from db and we will save them.
import cx_Oracle
db = cx_Oracle.connect('USER/PASSWORD@IP.address.machine:port_number/SID')
cursor = db.cursor()
cursor.execute("select image from table_name where value='xyz'")
row = cursor.fetchone()
dbimagefile=row[0]
blob= dbimagefile.read()
imageFile = open("image.jpg",'wb')
#write the data to the file
imageFile.write(blob)
imageFile.close()
cursor.close()
db.close()
In this example i'm saving jpg image from db to local machine..
if your file extension is different then change the extension and then every thing is same...
some of the extensions are like :
wsq
jp2
jpg
gif
doc
xml
json
If you still got any Q's for me feel free to comment will be happy to respond ..
Thanks your support...
No comments:
Post a Comment