Fix MAX_CONTENT_LENGTH configuration for large file uploads

- Explicitly set MAX_CONTENT_LENGTH in Flask app config during initialization
- Add logging to verify MAX_CONTENT_LENGTH is set correctly
- Fixes 'File too large' error for files over 500MB (now supports 5GB)
parent 7388278b
......@@ -239,19 +239,19 @@ class Config:
"""Initialize application with configuration and set up persistent directories"""
import logging
logger = logging.getLogger(__name__)
try:
if PERSISTENT_DIRS_AVAILABLE:
# Use the persistent directory system
directories = setup_persistent_directories()
logger.info(f"Set up persistent directories: {directories}")
# Update app config with actual directory paths
app.config['UPLOAD_FOLDER'] = str(directories['uploads'])
app.config['FIXTURES_UPLOAD_FOLDER'] = str(directories['fixtures'])
app.config['ZIP_UPLOAD_FOLDER'] = str(directories['zips'])
app.config['TEMP_UPLOAD_FOLDER'] = str(directories['temp'])
# Log PyInstaller detection
if is_pyinstaller():
logger.info("Running from PyInstaller executable - using persistent directories")
......@@ -264,12 +264,16 @@ class Config:
os.makedirs(Config.ZIP_UPLOAD_FOLDER, exist_ok=True)
os.makedirs(Config.TEMP_UPLOAD_FOLDER, exist_ok=True)
logger.warning("Persistent directory utilities not available - using fallback directory creation")
# Set MAX_CONTENT_LENGTH explicitly in app config
app.config['MAX_CONTENT_LENGTH'] = Config.MAX_CONTENT_LENGTH
logger.info(f"Set MAX_CONTENT_LENGTH to {Config.MAX_CONTENT_LENGTH} bytes ({Config.MAX_CONTENT_LENGTH // (1024*1024)} MB)")
# Create other necessary directories
os.makedirs(os.path.dirname(Config.DAEMON_PID_FILE), exist_ok=True)
os.makedirs(os.path.dirname(Config.DAEMON_LOG_FILE), exist_ok=True)
os.makedirs(Config.DAEMON_WORKING_DIR, exist_ok=True)
except Exception as e:
logger.error(f"Failed to initialize directories: {e}")
# Fallback to basic directory creation
......@@ -298,17 +302,17 @@ class ProductionConfig(Config):
@classmethod
def init_app(cls, app):
Config.init_app(app)
# Production-specific initialization
import logging
from logging.handlers import RotatingFileHandler
if not app.debug:
# Ensure log directory exists
log_file = app.config.get('DAEMON_LOG_FILE', cls.DAEMON_LOG_FILE)
log_dir = os.path.dirname(log_file)
os.makedirs(log_dir, exist_ok=True)
file_handler = RotatingFileHandler(
log_file,
maxBytes=10240000,
......@@ -317,7 +321,7 @@ class ProductionConfig(Config):
file_handler.setFormatter(logging.Formatter(cls.LOG_FORMAT))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
# Log production startup info
logger = logging.getLogger(__name__)
logger.info("Production configuration initialized")
......@@ -325,6 +329,7 @@ class ProductionConfig(Config):
logger.info(f"Using persistent directories - PyInstaller: {is_pyinstaller()}")
logger.info(f"Upload folder: {app.config.get('UPLOAD_FOLDER', cls.UPLOAD_FOLDER)}")
logger.info(f"Log file: {log_file}")
logger.info(f"MAX_CONTENT_LENGTH: {app.config.get('MAX_CONTENT_LENGTH', 'not set')}")
class TestingConfig(Config):
"""Testing configuration"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment