From 19d68252cd353ff3c69ada5bf90fb75078a0ec83 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Wed, 2 Apr 2025 16:36:58 +0530 Subject: [PATCH] (fix/attach): inputs are created in application --- application/api/user/routes.py | 12 +++++------- application/worker.py | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 1e0d13fe..8f374aa7 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -2508,19 +2508,17 @@ class StoreAttachment(Resource): try: original_filename = secure_filename(file.filename) folder_name = original_filename - + save_dir = os.path.join(current_dir, settings.UPLOAD_FOLDER, user, "attachments",folder_name) + os.makedirs(save_dir, exist_ok=True) # Create directory structure: user/attachments/filename/ - base_dir = os.path.join(current_dir, settings.UPLOAD_FOLDER, user, "attachments", folder_name) - os.makedirs(base_dir, exist_ok=True) - - file_path = os.path.join(base_dir, original_filename) + file_path = os.path.join(save_dir, original_filename) # Handle filename conflicts if os.path.exists(file_path): name_parts = os.path.splitext(original_filename) timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S") new_filename = f"{name_parts[0]}_{timestamp}{name_parts[1]}" - file_path = os.path.join(base_dir, new_filename) + file_path = os.path.join(save_dir, new_filename) original_filename = new_filename file.save(file_path) @@ -2529,7 +2527,7 @@ class StoreAttachment(Resource): # Start async task to process single file task = store_attachment.delay( - os.path.abspath(os.path.join(current_dir, settings.UPLOAD_FOLDER)), + save_dir, file_info, user ) diff --git a/application/worker.py b/application/worker.py index 03180d5d..23ff0422 100755 --- a/application/worker.py +++ b/application/worker.py @@ -342,8 +342,7 @@ def attachment_worker(self, directory, file_info, user): folder_name = file_info["folder"] filename = file_info["filename"] - base_dir = os.path.join(directory, user, "attachments", folder_name) - file_path = os.path.join(base_dir, filename) + file_path = os.path.join(directory, filename) logging.info(f"Processing file: {file_path}", extra={"user": user, "job": job_name})