How can I store binary data io.BytesIO()
in SQLlite DB using peewee
?
When I try to store it in BlobField I'm getting following error:
ValueError: Value must be either a bytes, memoryview or BigBitFieldData instance.
How can I store binary data io.BytesIO()
in SQLlite DB using peewee
?
When I try to store it in BlobField I'm getting following error:
ValueError: Value must be either a bytes, memoryview or BigBitFieldData instance.
It appears that you're not actually using a BlobField
. However, to store data from a BytesIO object into an actual BlobField
, you can:
# io.BytesIO.getvalue() method should return bytes.
some_model.blob_field = bytesio_obj.getvalue()
Building on the author's answer, I am putting a more end-to-end example here for people who aren't familiar with this the io
with open("file.parquet.gzip", "rb") as f:
bytesio_obj = io.BytesIO(f.read())
binary = bytesio_obj.getvalue()
some_model.blob_field = binary