(feat:fs_abstract) attachment uploads

This commit is contained in:
ManishMadan2882
2025-04-17 02:35:45 +05:30
parent 377e33c148
commit 0a0e16547e
3 changed files with 63 additions and 63 deletions

View File

@@ -2494,7 +2494,6 @@ class StoreAttachment(Resource):
if not decoded_token:
return make_response(jsonify({"success": False}), 401)
# Get single file instead of list
file = request.files.get("file")
if not file or file.filename == "":
@@ -2508,29 +2507,18 @@ class StoreAttachment(Resource):
try:
attachment_id = ObjectId()
original_filename = secure_filename(file.filename)
relative_path = f"{settings.UPLOAD_FOLDER}/{user}/attachments/{str(attachment_id)}/{original_filename}"
save_dir = os.path.join(
current_dir,
settings.UPLOAD_FOLDER,
user,
"attachments",
str(attachment_id)
)
os.makedirs(save_dir, exist_ok=True)
file_content = file.read()
file_path = os.path.join(save_dir, original_filename)
file.save(file_path)
file_info = {
"filename": original_filename,
"attachment_id": str(attachment_id)
"attachment_id": str(attachment_id),
"path": relative_path,
"file_content": file_content
}
current_app.logger.info(f"Saved file: {file_path}")
# Start async task to process single file
task = store_attachment.delay(
save_dir,
file_info,
user
)
@@ -2543,7 +2531,6 @@ class StoreAttachment(Resource):
}),
200
)
except Exception as err:
current_app.logger.error(f"Error storing attachment: {err}")
return make_response(jsonify({"success": False, "error": str(err)}), 400)

View File

@@ -23,8 +23,8 @@ def schedule_syncs(self, frequency):
@celery.task(bind=True)
def store_attachment(self, directory, saved_files, user):
resp = attachment_worker(self, directory, saved_files, user)
def store_attachment(self, file_info, user):
resp = attachment_worker(self, file_info, user)
return resp