costapy/scripts/uploader.py

12 lines
390 B
Python
Raw Normal View History

2026-04-16 15:28:50 +07:00
import os
def upload(file, directory, new_name=None):
try:
os.makedirs(directory, exist_ok=True)
if not new_name:
new_name = file.filename
full_path = os.path.join(directory, new_name)
file.save(full_path)
return {"status": "success", "path": full_path}
except Exception as e:
return {"status": "failed", "error": str(e)}