diff --git a/api/core/tools/provider/builtin/imageloader/tools/url_to_img.py b/api/core/tools/provider/builtin/imageloader/tools/url_to_img.py index 0a5e3b0c6ae3bc..cd0a8137ae53cb 100644 --- a/api/core/tools/provider/builtin/imageloader/tools/url_to_img.py +++ b/api/core/tools/provider/builtin/imageloader/tools/url_to_img.py @@ -42,15 +42,21 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv file_key = f"tools/{tenant_id}/{filename}{image_ext}" mime_type, _ = guess_type(file_key) + size = 0 if not storage.exists(file_key): response = requests.get(url, stream=True) if response.status_code == 200: storage.save(file_key, response.content) + size = len(response.content) else: raise ToolInvokeError(f"Request failed with status code {response.status_code} and {response.text}") # sign_url = ToolFileManager.sign_file(file.file_key, image_ext) + else: + blob = storage.load_once(file_key) + size = len(blob) + _ = ToolFileManager.create_file_by_key( id=filename, user_id=user_id, @@ -59,9 +65,13 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> list[ToolInv file_key=file_key, mimetype=mime_type, name=filename, - size=len(response.content) + size=size ) + sign_url = ToolFileManager.sign_file(tool_file_id=filename, extension=image_ext) + + url = sign_url + meta = { "url": url, "tool_file_id": filename,