0
병을 통해 이미지를 업로드하려고하고 psycopg2와 함께 포스트 그레스 BYTEA
열에 삽입하려고합니다. 이 오류 :"BYTEA 열에 이미지를 삽입하려고 할 때"_io.BufferedRandom을 이진수로 이스케이프 할 수 없음 "
TypeError: can't escape _io.BufferedRandom to binary
데이터를 삽입 할 라인에서 cursor.excute()
.
@route('/images', method='POST')
def upload_image():
upload = request.files.get('image')
img = Image.open(upload.file) # Pillow
binary = psycopg2.Binary(upload.file)
cursor = connection.cursor()
id = cursor.execute(
'''
INSERT INTO image (filename, data, width, height)
VALUES (%s, %s, %s, %s)
RETURNING id
''',
(upload.filename, binary, img.width, img.height)
)
return id
내가 잘못 뭐하는 거지 :
여기 내 코드입니까?
죄송합니다. 되돌아 와서 이것을 받아들이는 걸 잊었습니다.'file.seek (0)'와 함께 잘 작동했습니다 :) –