diff --git a/file_upload_service.py b/file_upload_service.py index 8ff4f45..1a92be1 100644 --- a/file_upload_service.py +++ b/file_upload_service.py @@ -30,7 +30,10 @@ ALLOWED_EXTENSIONS = {'jpg', 'jpeg', 'png', 'gif'} ALLOWED_MIME_TYPES = {'image/jpeg', 'image/png', 'image/gif'} MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB MAX_IMAGE_DIMENSIONS = (4096, 4096) # Max 4K resolution -UPLOAD_BASE_PATH = 'static/uploads/forum' + +# Get absolute path based on this file's location +_BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +UPLOAD_BASE_PATH = os.path.join(_BASE_DIR, 'static', 'uploads', 'forum') # Magic bytes for image validation IMAGE_SIGNATURES = { @@ -211,7 +214,7 @@ class FileUploadService: clean_img.save(file_path, **save_kwargs) file_size = os.path.getsize(file_path) - relative_path = os.path.relpath(file_path, 'static') + relative_path = os.path.relpath(file_path, os.path.join(_BASE_DIR, 'static')) logger.info(f"Saved forum attachment: {stored_filename} ({file_size} bytes)") return stored_filename, relative_path, file_size, mime_type @@ -222,7 +225,7 @@ class FileUploadService: file.seek(0) file.save(file_path) file_size = os.path.getsize(file_path) - relative_path = os.path.relpath(file_path, 'static') + relative_path = os.path.relpath(file_path, os.path.join(_BASE_DIR, 'static')) return stored_filename, relative_path, file_size, mime_type @staticmethod