HTTP request module does not process files through form-data in its body. #4225

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

Originally created by @murtaza-motorwala on GitHub (Jun 23, 2024).

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).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

In the HTTP request module, there is no way to add a file. I am trying to use "form-data" in the body, but it does not seem to upload the file for processing.

image

Note - And if we can get the file for processing from the "start" module, then that would be awesome.

✔️ Expected Behavior

The file should be uploaded in the HTTP request for further processing down the pipeline.

Actual Behavior

It does not process the file. It only processes the JSON body.

Originally created by @murtaza-motorwala on GitHub (Jun 23, 2024). ### 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] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce In the HTTP request module, there is no way to add a file. I am trying to use "form-data" in the body, but it does not seem to upload the file for processing. <img width="1439" alt="image" src="https://github.com/langgenius/dify/assets/171589201/d54f92a4-97f4-4fa8-a0c1-af5d6b13e49f"> Note - And if we can get the file for processing from the "start" module, then that would be awesome. ### ✔️ Expected Behavior The file should be uploaded in the HTTP request for further processing down the pipeline. ### ❌ Actual Behavior It does not process the file. It only processes the JSON body.
yindo added the 🐞 bug label 2026-02-21 18:05:18 -05:00
yindo closed this issue 2026-02-21 18:05:18 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 23, 2024):

Hey @murtaza-motorwala! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🤖

To resolve the issue where the HTTP request module in Dify version 0.6.11, self-hosted using Docker, does not process files through form-data in its body, ensure that the request is correctly formatted to handle multipart form-data. Here is an example of how to structure your cURL request for uploading a file:

curl --location --request POST 'http://your-dify-instance/api/datasets/{dataset_id}/document/create_by_file' \
--header 'Authorization: Bearer {api_key}' \
--form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
--form 'file=@"/path/to/file"'

Replace http://your-dify-instance/api with the actual base URL of your Dify instance, {dataset_id} with the actual dataset ID, {api_key} with your actual API key, and "/path/to/file" with the actual path to the file you want to upload [1][2].

Additionally, the "start" module in Dify handles file inputs using the sys.files system-built variable. This variable is used for file uploads within the conversation, such as uploading an image to understand its content. The workflow can be configured to pass these files to subsequent modules by integrating image understanding models or tools designed for processing image inputs [3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 23, 2024): <!-- Greeting --> Hey @murtaza-motorwala! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🤖 <!-- Answer --> To resolve the issue where the HTTP request module in Dify version 0.6.11, self-hosted using Docker, does not process files through form-data in its body, ensure that the request is correctly formatted to handle multipart form-data. Here is an example of how to structure your cURL request for uploading a file: ```bash curl --location --request POST 'http://your-dify-instance/api/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \ --form 'file=@"/path/to/file"' ``` Replace `http://your-dify-instance/api` with the actual base URL of your Dify instance, `{dataset_id}` with the actual dataset ID, `{api_key}` with your actual API key, and `"/path/to/file"` with the actual path to the file you want to upload <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/(commonLayout)/datasets/template/template.zh.mdx)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/(commonLayout)/datasets/template/template.en.mdx)</sup>. Additionally, the "start" module in Dify handles file inputs using the `sys.files` system-built variable. This variable is used for file uploads within the conversation, such as uploading an image to understand its content. The workflow can be configured to pass these files to subsequent modules by integrating image understanding models or tools designed for processing image inputs <sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/start.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/workflow/node/start.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@murtaza-motorwala commented on GitHub (Jun 23, 2024):

@dosu - This is helpful. Thank you. Is there a way you can provide an option in the GUI to upload the files for HTTP request? I am trying to create a pipeline where I would let the user upload the file and then I would use it to extract the text using OCR which will be use further down the pipeline for different purposes.

@murtaza-motorwala commented on GitHub (Jun 23, 2024): @dosu - This is helpful. Thank you. Is there a way you can provide an option in the GUI to upload the files for HTTP request? I am trying to create a pipeline where I would let the user upload the file and then I would use it to extract the text using OCR which will be use further down the pipeline for different purposes.
Author
Owner

@dosubot[bot] commented on GitHub (Jun 23, 2024):

Yes, it is possible to provide an option in the GUI to upload files for the HTTP request in Dify version 0.6.11, self-hosted with Docker. The DifyClient class includes a file_upload method that handles file uploads using multipart/form-data. This method can be integrated into the GUI to allow users to upload files.

Here is the relevant code snippet from the DifyClient class:

public function file_upload($user, $files) {
    $data = ['user' => $user];
    $options = [
        'multipart' => $this->prepareMultipart($data, $files)
    ];

    return $this->file_client->request('POST', 'files/upload', $options);
}

protected function prepareMultipart($data, $files) {
    $multipart = [];
    foreach ($data as $key => $value) {
        $multipart[] = [
            'name' => $key,
            'contents' => $value
        ];
    }

    foreach ($files as $file) {
        $multipart[] = [
            'name' => 'file',
            'contents' => fopen($file['tmp_name'], 'r'),
            'filename' => $file['name']
        ];
    }

    return $multipart;
}

Additionally, Dify's API documentation provides an example of how to create a document by uploading a file using a multipart/form-data request. This can be useful for integrating file upload functionality into the GUI:

curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_file' \
--header 'Authorization: Bearer {api_key}' \
--form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
--form 'file=@"/path/to/file"'

This code demonstrates how to handle file uploads, which can be utilized in the GUI to provide the necessary functionality [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 23, 2024): <!-- Answer --> Yes, it is possible to provide an option in the GUI to upload files for the HTTP request in Dify version 0.6.11, self-hosted with Docker. The `DifyClient` class includes a `file_upload` method that handles file uploads using multipart/form-data. This method can be integrated into the GUI to allow users to upload files. Here is the relevant code snippet from the `DifyClient` class: ```php public function file_upload($user, $files) { $data = ['user' => $user]; $options = [ 'multipart' => $this->prepareMultipart($data, $files) ]; return $this->file_client->request('POST', 'files/upload', $options); } protected function prepareMultipart($data, $files) { $multipart = []; foreach ($data as $key => $value) { $multipart[] = [ 'name' => $key, 'contents' => $value ]; } foreach ($files as $file) { $multipart[] = [ 'name' => 'file', 'contents' => fopen($file['tmp_name'], 'r'), 'filename' => $file['name'] ]; } return $multipart; } ``` Additionally, Dify's API documentation provides an example of how to create a document by uploading a file using a multipart/form-data request. This can be useful for integrating file upload functionality into the GUI: ```bash curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_file' \ --header 'Authorization: Bearer {api_key}' \ --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \ --form 'file=@"/path/to/file"' ``` This code demonstrates how to handle file uploads, which can be utilized in the GUI to provide the necessary functionality <sup>[[1]](https://github.com/langgenius/dify/blob/main/sdks/php-client/dify-client.php)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/(commonLayout)/datasets/template/template.zh.mdx)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@murtaza-motorwala commented on GitHub (Jun 23, 2024):

@dosu - Can this be added an an enhancement in the next release please ?

@murtaza-motorwala commented on GitHub (Jun 23, 2024): @dosu - Can this be added an an enhancement in the next release please ?
Author
Owner

@dosubot[bot] commented on GitHub (Jun 23, 2024):

@takatost, this one's a bit out of my wheelhouse, could you step in and provide your guidance?

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 23, 2024): <!-- Answer --> @takatost, this one's a bit out of my wheelhouse, could you step in and provide your guidance? <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Jun 23, 2024):

We will use a unique node to process files in the future.

@crazywoola commented on GitHub (Jun 23, 2024): We will use a unique node to process files in the future.
Author
Owner

@crazywoola commented on GitHub (Jun 23, 2024):

See https://github.com/langgenius/dify/issues/5432

@crazywoola commented on GitHub (Jun 23, 2024): See https://github.com/langgenius/dify/issues/5432
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4225