I'm trying to upload a zip file to my server using python flask request and then unzip it using zipfile module.
Here is my code:
@app.route('/uoload', methods=['POST'])
def upload ():
data = request.data
current_path = os.getcwd()
filename = "file.zip"
with open(os.path.join(upload_path, filename), 'w') as file:
file.write(data)
try:
with zipfile.ZipFile(os.path.join(current_path + filename)) as zf:
zf.extractall(os.path.join(upload_path))
except BadZipfile as e:
print e
return "", 406
But it seems like the uploaded file is damaged somehow. Because when i'm trying to unzip it, BadzipFile exception occurs and it says : "Bad magic number for file header" .