From 7be020916920caa006459bcf58f5b83839cb60ce Mon Sep 17 00:00:00 2001 From: Kavalar Date: Mon, 30 Oct 2023 02:29:47 +0300 Subject: [PATCH] fix save file --- server.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 7b31589..df13031 100644 --- a/server.py +++ b/server.py @@ -1,3 +1,4 @@ +import pathlib from typing import Union, Annotated import uvicorn from routes.user_routes import user_route @@ -78,12 +79,15 @@ async def create_upload_file(file: UploadFile | None, package: Annotated[str, Fo os.makedirs(dir_last) if not os.path.exists(dir_stable): os.makedirs(dir_stable) - with open(f"{dir_file}/{filename}", 'w') as f: + os.remove(f"{dir_file}/{filename}") + with open(f"{dir_file}/{filename}", 'a') as f: f.write(str(contents)) - with open(f"{dir_last}/{filename}", 'w') as f: + os.remove(f"{dir_last}/{filename}") + with open(f"{dir_last}/{filename}", 'a') as f: f.write(str(contents)) if stable: - with open(f"{dir_stable}/{filename}", 'w') as f: + os.remove(f"{dir_stable}/{filename}") + with open(f"{dir_stable}/{filename}", 'a') as f: f.write(str(contents)) except Exception as err: return {"message": "There was an error uploading the file, error {err}".format(err=err)}