lundi 4 mars 2019

How can I save image object in the data base?

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 ( email varchar(100) COLLATE utf8_bin DEFAULT NULL, project_name varchar(200) COLLATE utf8_bin NOT NULL, panelimg longblob NOT NULL, status int(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 = 'snoo@gmail.com'")

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




Aucun commentaire:

Enregistrer un commentaire