I have a BLOB image in Cloud Server and I want to display it using Tkinter.Label()
Before diving into code I must tell blob file exist in mysql table and record
itself does store
a row from table correctly. records[0][2]
stands for /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwI...
Here is the code snippet:
global img
#Connecting Server
mydb= mysql.connector.connect(**config)
cursor = mydb.cursor(buffered=True)
#Fetching Blob Image to Record
sql_fetch_blob_query = """SELECT * from my-Table where id = %s"""
emp_id=4
cursor.execute(sql_fetch_blob_query, (emp_id,))
record = cursor.fetchall()
#Base64 Encoding
base64_encoded= base64.b64encode(record[0][2])
base64_encoded_string= base64_encoded.decode('utf-8')
#Displaying on Tkinter
root=tk.Tk()
img=tk.PhotoImage(data=base64_encoded_string)
myLabel= tk.Label(root,image=img)
myLabel.pack()
root.mainLoop()
And here is the error i get:
_tkinter.TclError: couldn't recognize image data
onimg=tk.PhotoImage(data=base64_encoded_string)
line
I tried changing that line to img=tk.PhotoImage(data=record[0][2])
and still the same error.
EDIT:
I print record[0][2]
before encoding and the output is: b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\