From adf54839c98a2a82e12a0ee8ab12cbc0da51e6db Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Mon, 30 Jan 2023 20:10:50 +0700 Subject: [PATCH] Update the uplaod function --- core/uploading.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/uploading.py b/core/uploading.py index 020d964..2330a8a 100644 --- a/core/uploading.py +++ b/core/uploading.py @@ -2,6 +2,10 @@ import os import cherrypy def main(file, rename, directory): + try: + os.makedirs(directory, exist_ok=True) + except OSError as error: + print(error) try: upload_path = directory upload_filename = file.filename @@ -9,6 +13,15 @@ def main(file, rename, directory): upload_file = os.path.normpath(os.path.join(upload_path, upload_rename)) upload_size = 0 + print("UPLOADING CORE: Directory: "+directory+"/"+rename) + if (os.path.isfile(directory+"/"+rename)): + print("UPLOADING CORE: Is exists! Removing!") + try: + os.remove(directory+"/"+rename) + except Exception as e: + print(f"UPLOADING CORE: removing failed: {e}") + else: + print("UPLOADING CORE: Is not exists! Removing skipped!") with open(upload_file, 'wb') as upload_result: while True: data = file.file.read(8192) @@ -22,6 +35,6 @@ def main(file, rename, directory): print("UPLOAD RENAME: " + str(upload_rename)) print("UPLOAD FILE: " + str(upload_file)) print("UPLOAD SIZE: " + str(upload_size)) - + except Exception as e: - print(f"ERROR: {e}") + print(f"ERROR CORE UPLOADING: {e}")