From 7f2e18be0c481fa0aa07b61c32af06696834a12a Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Sun, 10 Aug 2025 14:02:00 +0800 Subject: [PATCH] move file chunk size check ahead --- api/core/plugin/impl/tool.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/core/plugin/impl/tool.py b/api/core/plugin/impl/tool.py index 6f0e47d44a..8cf073e364 100644 --- a/api/core/plugin/impl/tool.py +++ b/api/core/plugin/impl/tool.py @@ -150,6 +150,11 @@ class PluginToolManager(BasePluginClient): meta=resp.meta, ) else: + # Check if single chunk is too large (8KB limit) + if len(blob_data) > 8192: + # Skip yielding this message + raise ValueError("File chunk is too large which reached the limit of 8KB") + # Check if file is too large if files[chunk_id].bytes_written + len(blob_data) > dify_config.TOOL_FILE_MAX_SIZE: # Delete the file if it's too large @@ -157,11 +162,6 @@ class PluginToolManager(BasePluginClient): # Skip yielding this message raise ValueError("File is too large which reached the limit of 30MB") - # Check if single chunk is too large (8KB limit) - if len(blob_data) > 8192: - # Skip yielding this message - raise ValueError("File chunk is too large which reached the limit of 8KB") - # Append the blob data to the buffer files[chunk_id].data[ files[chunk_id].bytes_written : files[chunk_id].bytes_written + len(blob_data)