I am using FastAPI to retrieve the docx file from the frontend as bytes file and to save it on the backend's filesystem. For this purpose I installed the python-docx library. However, when I am trying to run the following code, just like it is said in python-docx docs (https://python-docx.readthedocs.io/en/latest/user/documents.html#opening-a-file-like-document)
async def create_file(textfile: UploadFile, user):
path = os.path.abspath(textfile.filename)
f = open(textfile.filename, 'rb')
document = Document(f)
f.close()
It throws an error:
zipfile.BadZipFile: File is not a zip file
I tried to use the following solution (https://stackoverflow.com/a/11385480/21602190) but as I use bytes, it is pointless.