Skip to content Skip to sidebar Skip to footer

Python Pyqt5: Store Image Data Into A Phpmyadmin Database

I want to upload a .png file into my database. fileName = QFileDialog().getOpenFileName() filePath = str(fileName[0]) # Path of the image data self.myImage = file

Solution 1:

You just need to read the image file and store the data as a blob in the database:

withopen(filePath, 'rb') as stream:
    blob= stream.read()
    cur.execute("INSERT INTO mytable VALUES(%s)", [blob])

To convert the blob into a pixmap:

pixmap = QtGui.QPixmap()
pixmap.loadFromData(blob)

Post a Comment for "Python Pyqt5: Store Image Data Into A Phpmyadmin Database"