Some types of image URL that tool plugin return may be parsed as .bin instead of image #12711

Closed
opened 2026-02-21 19:08:40 -05:00 by yindo · 1 comment
Owner

Originally created by @QunBB on GitHub (Apr 9, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.2.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

develope a custom tool plugin and return remote an image url in some formats like the below example url, and dify-api will parse it as a .bin file instead of image.

class CustomTool(Tool):
    def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage, None, None]:
        
        ......
        
        yield self.create_image_message(image_url)

you could test it using this image_url: https://img0.baidu.com/it/u=816951757,2244085608&fm=253&fmt=auto&app=120&f=JPEG?w=1158&h=800

Image

✔️ Expected Behavior

When the tool plugin return a remote image_url in various formats, it should be parsed as image instead of .bin file

Actual Behavior

When the tool plugin return a remote image_url like https://img0.baidu.com/it/u=816951757,2244085608&fm=253&fmt=auto&app=120&f=JPEG?w=1158&h=800, it would be parsed as .bin file.

Originally created by @QunBB on GitHub (Apr 9, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.2.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce develope a custom tool plugin and return remote an image url in some formats like the below example url, and dify-api will parse it as a .bin file instead of image. ```python class CustomTool(Tool): def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage, None, None]: ...... yield self.create_image_message(image_url) ``` you could test it using this image_url: `https://img0.baidu.com/it/u=816951757,2244085608&fm=253&fmt=auto&app=120&f=JPEG?w=1158&h=800` <img width="401" alt="Image" src="https://github.com/user-attachments/assets/3b1ed36c-bfa7-4e3f-a260-6890a1a5a739" /> ### ✔️ Expected Behavior When the tool plugin return a remote image_url in various formats, it should be parsed as image instead of .bin file ### ❌ Actual Behavior When the tool plugin return a remote image_url like `https://img0.baidu.com/it/u=816951757,2244085608&fm=253&fmt=auto&app=120&f=JPEG?w=1158&h=800`, it would be parsed as .bin file.
yindo added the 🔨 feat:tools label 2026-02-21 19:08:40 -05:00
yindo closed this issue 2026-02-21 19:08:40 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 9, 2025):

The issue you're experiencing, where some image URLs are parsed as .bin files instead of images, may be related to how Dify determines the file type when downloading an image from a URL. Dify uses several methods to guess the file type, including:

  1. Extracting the filename from the URL path.
  2. Checking the Content-Disposition header for a filename.
  3. Generating a unique filename if none is found.
  4. Guessing the MIME type based on the filename and URL using mimetypes.guess_type().
  5. Using the Content-Type header from the response if MIME type guessing fails.
  6. Using python-magic for content-based MIME type detection if the MIME type is still unknown or generic.

If the MIME type is detected as "application/octet-stream" and no suitable extension is found, the file may default to a .bin extension [1][2].

To address this issue, you might want to ensure that the server hosting the image URL provides a correct Content-Type header. Additionally, you could consider using python-magic for more accurate MIME type detection if it's not already enabled in your setup.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 9, 2025): <!-- Answer --> The issue you're experiencing, where some image URLs are parsed as `.bin` files instead of images, may be related to how Dify determines the file type when downloading an image from a URL. Dify uses several methods to guess the file type, including: 1. Extracting the filename from the URL path. 2. Checking the `Content-Disposition` header for a filename. 3. Generating a unique filename if none is found. 4. Guessing the MIME type based on the filename and URL using `mimetypes.guess_type()`. 5. Using the `Content-Type` header from the response if MIME type guessing fails. 6. Using `python-magic` for content-based MIME type detection if the MIME type is still unknown or generic. If the MIME type is detected as "application/octet-stream" and no suitable extension is found, the file may default to a `.bin` extension <sup>[[1]](https://github.com/langgenius/dify/issues/12551)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/controllers/common/helpers.py)</sup>. To address this issue, you might want to ensure that the server hosting the image URL provides a correct `Content-Type` header. Additionally, you could consider using `python-magic` for more accurate MIME type detection if it's not already enabled in your setup. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2020ab1d-b22f-4769-b362-5991feac094a?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12711