T
T
Timyr2894372020-12-15 21:24:27
SQLite
Timyr289437, 2020-12-15 21:24:27

How to remember image in sql lite?

I need to remember in sql lite table image here is my code but error

import sqlite3
con = sqlite3.connect('test.db')
cur = con.cursor()
# Получаем бинарные данные нашего файла
data = open("C:/new_project/images/test.jpg")
# Конвертируем данные
binary = sqlite3.Binary(data) ошибка вот тут и она вот такая (TypeError: memoryview: a bytes-like object is required, not '_io.TextIOWrapper')
# Готовим запрос в базу
cur.execute("INSERT INTO Images(Data) VALUES (?)", (binary,))
# Выполняем запрос
con.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-12-15
@Timyr289437

byte object will be obtained if the content is read in binary mode

data = open("C:/new_project/images/test.jpg","rb").read()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question