我想将一个zip文件存储在Postgres数据库中。该列的类型是bytea
当尝试获取JSON文件或CSV文件的字节时,可以使用以下方法:
with open(filename, encoding='utf-8') as file_data:
bytes_content = file_data.read()
但是,如果我尝试压缩文件或者xls文件,就会出现错误。
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 14: invalid continuation byte
我进行了一些搜索,建议更改编码类型,我尝试了latin-1
和ISO-8859-1
,但都导致错误。
ValueError: A string literal cannot contain NUL (0x00) characters.
有想法如何获取zip文件的字节,以便将其存储在postgres数据库中吗?