fix: Use absolute paths in file_upload_service for PROD compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-01-10 21:30:03 +01:00
parent 1b15a578e2
commit 957fff3f2f

View File

@ -30,7 +30,10 @@ ALLOWED_EXTENSIONS = {'jpg', 'jpeg', 'png', 'gif'}
ALLOWED_MIME_TYPES = {'image/jpeg', 'image/png', 'image/gif'} ALLOWED_MIME_TYPES = {'image/jpeg', 'image/png', 'image/gif'}
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
MAX_IMAGE_DIMENSIONS = (4096, 4096) # Max 4K resolution 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 # Magic bytes for image validation
IMAGE_SIGNATURES = { IMAGE_SIGNATURES = {
@ -211,7 +214,7 @@ class FileUploadService:
clean_img.save(file_path, **save_kwargs) clean_img.save(file_path, **save_kwargs)
file_size = os.path.getsize(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'))
logger.info(f"Saved forum attachment: {stored_filename} ({file_size} bytes)") logger.info(f"Saved forum attachment: {stored_filename} ({file_size} bytes)")
return stored_filename, relative_path, file_size, mime_type return stored_filename, relative_path, file_size, mime_type
@ -222,7 +225,7 @@ class FileUploadService:
file.seek(0) file.seek(0)
file.save(file_path) file.save(file_path)
file_size = os.path.getsize(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 return stored_filename, relative_path, file_size, mime_type
@staticmethod @staticmethod