AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): Truncate filenames with excessively long 'extensions' (#12025)
DEEVEN SERU1d7282b5f3c3
diff --git a/autogpt_platform/backend/backend/util/file.py b/autogpt_platform/backend/backend/util/file.pyindex 4f056471f2..16e04dcc24 100644--- a/autogpt_platform/backend/backend/util/file.py+++ b/autogpt_platform/backend/backend/util/file.py@@ -71,11 +71,15 @@ def sanitize_filename(filename: str) -> str:# Truncate if too longif len(sanitized) > MAX_FILENAME_LENGTH:- # Keep the extension if possible+ # Keep the extension if possible, but only if it's reasonable lengthif "." in sanitized:name, ext = sanitized.rsplit(".", 1)- max_name_length = MAX_FILENAME_LENGTH - len(ext) - 1- sanitized = name[:max_name_length] + "." + ext+ # If extension is too long, it's likely not a file extension but just text+ if len(ext) <= 20:+ max_name_length = MAX_FILENAME_LENGTH - len(ext) - 1+ sanitized = name[:max_name_length] + "." + ext+ else:+ sanitized = sanitized[:MAX_FILENAME_LENGTH]else:sanitized = sanitized[:MAX_FILENAME_LENGTH]@@ -129,7 +133,7 @@ async def store_media_file(Return format options:- "for_local_processing": Returns local file path - use with ffmpeg, MoviePy, PIL, etc.- - "for_external_api": Returns data URI (base64) - use when sending to external APIs+ - "for_external_api": Returns data URI (base64) - use when sending content to external APIs- "for_block_output": Returns best format for output - workspace:// in CoPilot, data URI in graphs:param file: Data URI, URL, workspace://, or local (relative) path.