I have a python code and I want to save an image into the database and this image is an object (Image)
Here is my table which I want to save on it
CREATE TABLE
project(project_namevarchar(200) COLLATE utf8_bin NOT NULL,panelimglongblob NOT NULL,statusint(1) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
and here is what I write but it didn't work correctly
conv = convertToBinaryData(origimg)
cursor.execute("UPDATE project SET panelimg=origimg where status = 0 and email = '[email protected]'")
where the origimage in the image as the object (Image)
and here is the function of the convert to binary :
def convertToBinaryData(filename):
#Convert digital data to binary format
with open(filename, 'rb') as file:
binaryData = file.read()
return binaryData
I got this error, so I need help
File "K-mean4-draw6-database.py", line 17, in convertToBinaryData with open(filename, 'rb') as file: TypeError: expected str, bytes or os.PathLike object, not Image
any suggestions please, Thank you