The bug with uploading files using form-data in the HTTP request within the workflow #7991

Closed
opened 2026-02-21 18:23:23 -05:00 by yindo · 4 comments
Owner

Originally created by @jianghengxiang on GitHub (Feb 5, 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

0.15.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a Workflow App.
  2. Set a single file parameter and a file list parameter in the start node.
  3. Use an HTTP request to call a POST interface with form-data, where the parameters are file1 and file2, corresponding to the two parameters in the start node.
  4. The workflow end node outputs the return value of the POST API.
  5. When running this workflow, it will be found that only one file parameter is passed, and the file list parameter is ignored.
  6. Upon checking the code, it was found that there is an issue in the _init_body method in the executor.py under http_request, as shown in the screenshot. When constructing the files variable, the file list parameter is being ignored.

Image

✔️ Expected Behavior

correctly execute the HTTP request and successfully pass both the single file parameter and the file list parameter from the start node to the HTTP request node, and then successfully call the POST API

Actual Behavior

only single file parameter can use in HTTP request node

Originally created by @jianghengxiang on GitHub (Feb 5, 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 0.15.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. Create a Workflow App. 2. Set a single file parameter and a file list parameter in the start node. 3. Use an HTTP request to call a POST interface with form-data, where the parameters are file1 and file2, corresponding to the two parameters in the start node. 4. The workflow end node outputs the return value of the POST API. 5. When running this workflow, it will be found that only one file parameter is passed, and the file list parameter is ignored. 6. Upon checking the code, it was found that there is an issue in the _init_body method in the executor.py under http_request, as shown in the screenshot. When constructing the files variable, the file list parameter is being ignored. ![Image](https://github.com/user-attachments/assets/797f4f1c-8590-4698-94eb-2f0208e0db6f) ### ✔️ Expected Behavior correctly execute the HTTP request and successfully pass both the single file parameter and the file list parameter from the start node to the HTTP request node, and then successfully call the POST API ### ❌ Actual Behavior only single file parameter can use in HTTP request node
yindo added the 🐞 buggood first issue labels 2026-02-21 18:23:23 -05:00
yindo closed this issue 2026-02-21 18:23:23 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 5, 2025):

@jianghengxiang Hello there! I'm here to help you out with any bugs, questions, or contributions you may have. Let's work together to resolve the issue you're facing.

To address the issue with the file list parameter being ignored in the HTTP request using form-data, ensure that the self.files attribute in the _init_body method of executor.py is correctly populated. Here's a breakdown of what you should check:

  1. File Selectors: Ensure that the file_selectors dictionary is correctly populated with keys and file selectors from the data items of type file. This is crucial for the self.files attribute to be set correctly.

  2. Populating self.files: The current implementation should populate self.files as follows:

    files: dict[str, Any] = {}
    files = {k: self.variable_pool.get_file(selector) for k, selector in file_selectors.items()}
    files = {k: v for k, v in files.items() if v is not None}
    files = {k: variable.value for k, variable in files.items() if variable is not None}
    files = {
        k: (v.filename, file_manager.download(v), v.mime_type or "application/octet-stream")
        for k, v in files.items()
        if v.related_id is not None
    }
    self.files = files or None
    

    Ensure that this code correctly processes both single file and file list parameters.

  3. HTTP Request Arguments: Verify that the request_args in the _do_http_request method includes the files parameter:

    request_args = {
        "url": self.url,
        "data": self.data,
        "files": self.files,
        "json": self.json,
        "content": self.content,
        "headers": headers,
        "params": self.params,
        "timeout": (self.timeout.connect, self.timeout.read, self.timeout.write),
        "follow_redirects": True,
        "max_retries": self.max_retries,
    }
    

    Ensure self.files is not None and contains the expected file data when the HTTP request is made.

If the issue persists, further debugging may be required to trace the flow of data and ensure that files are correctly handled and included in the request [1].

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Feb 5, 2025): <!-- Greeting --> @jianghengxiang Hello there! I'm here to help you out with any bugs, questions, or contributions you may have. Let's work together to resolve the issue you're facing. <!-- Answer --> To address the issue with the file list parameter being ignored in the HTTP request using form-data, ensure that the `self.files` attribute in the `_init_body` method of `executor.py` is correctly populated. Here's a breakdown of what you should check: 1. **File Selectors**: Ensure that the `file_selectors` dictionary is correctly populated with keys and file selectors from the `data` items of type `file`. This is crucial for the `self.files` attribute to be set correctly. 2. **Populating `self.files`**: The current implementation should populate `self.files` as follows: ```python files: dict[str, Any] = {} files = {k: self.variable_pool.get_file(selector) for k, selector in file_selectors.items()} files = {k: v for k, v in files.items() if v is not None} files = {k: variable.value for k, variable in files.items() if variable is not None} files = { k: (v.filename, file_manager.download(v), v.mime_type or "application/octet-stream") for k, v in files.items() if v.related_id is not None } self.files = files or None ``` Ensure that this code correctly processes both single file and file list parameters. 3. **HTTP Request Arguments**: Verify that the `request_args` in the `_do_http_request` method includes the `files` parameter: ```python request_args = { "url": self.url, "data": self.data, "files": self.files, "json": self.json, "content": self.content, "headers": headers, "params": self.params, "timeout": (self.timeout.connect, self.timeout.read, self.timeout.write), "follow_redirects": True, "max_retries": self.max_retries, } ``` Ensure `self.files` is not `None` and contains the expected file data when the HTTP request is made. If the issue persists, further debugging may be required to trace the flow of data and ensure that files are correctly handled and included in the request <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/http_request/executor.py)</sup>. <!-- 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/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/30811824-e1f5-4acf-9e7b-fc1f3b2d8dc6?feedback_type=other)</sup>
Author
Owner

@jianghengxiang commented on GitHub (Feb 5, 2025):

@crazywoola

thanks,but the file_selectors dictionary is correctly,The issue lies in this line of code:
files = {k: self.variable_pool.get_file(selector) for k, selector in file_selectors.items()}

when executing this method:
self.variable_pool.get_file(selector)

def get_file(self, selector: Sequence[str], /) -> FileSegment | None:
        segment = self.get(selector)
        if isinstance(segment, FileSegment):
            return segment
        return None

The code only checks for the FileSegment type, while the actual file list parameter is of the ArrayFileSegment type. As a result, when attempting to retrieve the file, it returns None.

Image
@jianghengxiang commented on GitHub (Feb 5, 2025): @crazywoola thanks,but the `file_selectors` dictionary is correctly,The issue lies in this line of code: `files = {k: self.variable_pool.get_file(selector) for k, selector in file_selectors.items()}` when executing this method: **`self.variable_pool.get_file(selector)`** ``` def get_file(self, selector: Sequence[str], /) -> FileSegment | None: segment = self.get(selector) if isinstance(segment, FileSegment): return segment return None ``` The code only checks for the `FileSegment` type, while the actual file list parameter is of the `ArrayFileSegment` type. As a result, when attempting to retrieve the file, it returns None. <img width="1305" alt="Image" src="https://github.com/user-attachments/assets/a3be6b63-614b-4b60-b529-d093c5ffc039" />
Author
Owner

@dosubot[bot] commented on GitHub (Mar 14, 2025):

Hi, @jianghengxiang. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • A bug in Dify version 0.15.2 affects HTTP requests using form-data, specifically with file list parameters.
  • The problem is traced to the _init_body method in executor.py.
  • You identified that self.variable_pool.get_file(selector) only checks for FileSegment type, not ArrayFileSegment, causing issues.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Mar 14, 2025): Hi, @jianghengxiang. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - A bug in Dify version 0.15.2 affects HTTP requests using form-data, specifically with file list parameters. - The problem is traced to the `_init_body` method in `executor.py`. - You identified that `self.variable_pool.get_file(selector)` only checks for `FileSegment` type, not `ArrayFileSegment`, causing issues. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Author
Owner

@crazywoola commented on GitHub (Mar 24, 2025):

Do you still have this issue?

@crazywoola commented on GitHub (Mar 24, 2025): Do you still have this issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7991