My python/flask app hosted on heroku (linux environment) encounters some issues when I upload a zip file from a windows client and trying to extract it. I get the following error :
Traceback (most recent call last):
2022-05-27T18:53:45.200198+00:00 app[web.1]: File "/app/app.py", line 2884, in verify_file
2022-05-27T18:53:45.200199+00:00 app[web.1]: with zipfile.ZipFile(file_path, mode="r") as zf:
2022-05-27T18:53:45.200199+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/zipfile.py", line 1131, in __init__
2022-05-27T18:53:45.200199+00:00 app[web.1]: self._RealGetContents()
2022-05-27T18:53:45.200202+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/zipfile.py", line 1216, in _RealGetContents
2022-05-27T18:53:45.200202+00:00 app[web.1]: fp.seek(self.start_dir, 0)
2022-05-27T18:53:45.200202+00:00 app[web.1]: OSError: [Errno 22] Invalid argument
this error is triggered when my app trying to unzip the uploaded file :
ROOT_DIR_FOR_TEMPORARY_FILES = 'tmp'
if not os.path.exists(ROOT_DIR_FOR_TEMPORARY_FILES):
os.mkdir(ROOT_DIR_FOR_TEMPORARY_FILES)
file_uuid = uuid.uuid4().hex
file_dir = os.path.join(ROOT_DIR_FOR_TEMPORARY_FILES,file_uuid)
file_path = os.path.join(ROOT_DIR_FOR_TEMPORARY_FILES,file_uuid+".zip")
with open(file_path, "wb") as binary_file:
binary_file.write(file_content)
with zipfile.ZipFile(file_path, mode="r") as zf:
zf.extractall(ROOT_DIR_FOR_TEMPORARY_FILES+"/"+file_uuid)
zf.close()
Yet, this works without problem when I do it from a Mac OS client machine. I don't know why this error occurs when I upload from Windows.
I am using request.data
to get the content of the uploaded file and then pass to file_content
.
Any suggestion ?