Skip to content

Commit

Permalink
fix: imageLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorpion1221 committed Dec 24, 2024
1 parent 7e8234c commit f0a0b66
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion api/core/tools/provider/builtin/imageloader/tools/url_to_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit f0a0b66

Please sign in to comment.