I'm trying to delete .zip file from server directory right after client has downloaded it, but everytime I'm trying to execute 'os.remove' there's an error: "file is used by another process etc etc etc"
This code is inside 'app.route' method
if (buttonName == "downloadFactures"):
with ZipFile('sampleDir.zip', 'w') as zipObj:
for facturesData in notApprovedFactures:
zipObj.write(facturesData[2])
return send_from_directory(app.root_path, "sampleDir.zip", as_attachment=True)
else:
-- nothing important
I tried to do something like:
zipObj = ZipFile(blabla)
forLoop
zipObj.write
zipObj.close()
zipDownload = send_from_directory
os.remove(here's path for zipFile in server directory)
return zipDownload
but it didn't work, obviously it didn't work because file is still being used by client which is downloading this zip.
So here's my question if anyone know, how can I remove that created zipFile from my server directory after client download it?