I have following problem.
I`m reading Image column from SQLserver db instance. pymssql library is used for querying.
In binary variable you can find hexadecimal string:
I can save files in pdf, docx, pptx, png formats, but xlsx files are corrupted:
They have wrong size and cannot be opened. Files saved by script have prefix TMP_
from os.path import isfile, join, exists, getsize
from DealsSQL import DealsSQL
squel = DealsSQL()
files = squel.getAttachmentToUpload()
for file in files:
binary = file['Att_Binary']
file_name = file['Att_FullName']
deal_id = file['Att_DealCRMID']
att_id = file['Att_ID']
tmp_filename = join('TEMP_FILES', 'TMP_' + file_name)
with open(tmp_filename, "wb") as f:
f.write(binary)
f.close()
print(getsize(tmp_filename))