I have some excel and pdf files that can be opened and viewed correctly. They are probably old versions of both. However, after downloading these files from FTP and saving them to a Django FileField, they become damaged and can no longer be opened. All I need is to maintain the file as is during the transition.
Unfortunately, I can't share any of the files as they contain confidential information.
Here is the part of the code used to download and save the files:
with io.BytesIO() as f:
ftplib_connection.retrbinary('RETR ' + filename, f.write)
f.seek(0)
content_file = ContentFile(f.read(), filename) # Try f.getvalue(), f.getbuffer()
return content_file # This will be saved to a Django FileField
About the mimetypes, I used python-magic. All the pdf files are application/pdf. The excel files however are mostly application/CDFV2. Please note that I can open and view these files in their original state. The problem is after they are fetched from an FTP server and saved to a Django FIleField.