-1

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.
Leopoldo
  • 795
  • 2
  • 8
  • 23

2 Answers2

4

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()
smartexpert
  • 2,625
  • 3
  • 24
  • 41
coleifer
  • 24,887
  • 6
  • 60
  • 75
-2

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

Source: https://stackoverflow.com/a/59365168/5739514

Kermit
  • 4,922
  • 4
  • 42
  • 74