Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(files): update Content-Length handling for tool and remote files (#9649)

-LAN-d6e8290a1cbd
diff --git a/api/controllers/files/tool_files.py b/api/controllers/files/tool_files.py
index 104b7cd9bb0..a298701a2f8 100644
--- a/api/controllers/files/tool_files.py
+++ b/api/controllers/files/tool_files.py
@@ -42,10 +42,10 @@ class ToolFilePreviewApi(Resource):
stream,
mimetype=tool_file.mimetype,
direct_passthrough=True,
- headers={
- "Content-Length": str(tool_file.size),
- },
+ headers={},
)
+ if tool_file.size > 0:
+ response.headers["Content-Length"] = str(tool_file.size)
if args["as_attachment"]:
response.headers["Content-Disposition"] = f"attachment; filename={tool_file.name}"
diff --git a/api/controllers/web/file.py b/api/controllers/web/file.py
index c029a07707c..6eeaa0e3f07 100644
--- a/api/controllers/web/file.py
+++ b/api/controllers/web/file.py
@@ -46,7 +46,7 @@ class RemoteFileInfoApi(WebApiResource):
response = ssrf_proxy.head(decoded_url)
return {
"file_type": response.headers.get("Content-Type", "application/octet-stream"),
- "file_length": int(response.headers.get("Content-Length", 0)),
+ "file_length": int(response.headers.get("Content-Length", -1)),
}
except Exception as e:
return {"error": str(e)}, 400