how send uploaded file via api #12332

Closed
opened 2026-02-21 19:06:57 -05:00 by yindo · 2 comments
Owner

Originally created by @asrguru20 on GitHub (Mar 29, 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.5

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I am not enable send a .jpg .png uploaded file to a dify agent chat to external platform like n8n or stability ai
or to a webhook , how we can handle this job
at the moment should give only the file URL to do this not via local upload file

when I upload an image file like example.jpg in my dify chatbot what key is assigned to this file how we can send the example.jpg file through a HTTP request or swagger custom tool to external platform

✔️ Expected Behavior

to be able to send uploaded file to webhook

Actual Behavior

I am confused

Originally created by @asrguru20 on GitHub (Mar 29, 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.5 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I am not enable send a .jpg .png uploaded file to a dify agent chat to external platform like n8n or stability ai or to a webhook , how we can handle this job at the moment should give only the file URL to do this not via local upload file when I upload an image file like example.jpg in my dify chatbot what key is assigned to this file how we can send the example.jpg file through a HTTP request or swagger custom tool to external platform ### ✔️ Expected Behavior to be able to send uploaded file to webhook ### ❌ Actual Behavior I am confused
yindo closed this issue 2026-02-21 19:06:57 -05:00
Author
Owner

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

To send an uploaded file via API in Dify, you can use the file_upload method provided in the DifyClient class. This method uses the endpoint "/files/upload" to handle file uploads. Here's a basic example of how you might use this method:

def file_upload(self, user, files):
    data = {"user": user}
    return self._send_request_with_files(
        "POST", "/files/upload", data=data, files=files
    )

For sending files to external platforms, ensure your HTTP request is formatted to handle multipart form-data. Here's an example using cURL:

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"'

Replace '/path/to/file' with the actual path to your file and fill in the placeholders like ${props.apiBaseUrl}, {dataset_id}, and {api_key} with your specific values. This approach might help you configure your HTTP request node to include file attachments [1].

Regarding the file key, Dify assigns a unique identifier to each uploaded file by generating a UUID and combining it with the current tenant ID and file extension. The file key is constructed as follows:

file_uuid = str(uuid.uuid4())
file_key = "upload_files/" + (current_tenant_id or "") + "/" + file_uuid + "." + extension

This key is used to save the file in storage and is stored in the database as part of the UploadFile record [2].

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 (Mar 29, 2025): <!-- Answer --> To send an uploaded file via API in Dify, you can use the `file_upload` method provided in the `DifyClient` class. This method uses the endpoint `"/files/upload"` to handle file uploads. Here's a basic example of how you might use this method: ```python def file_upload(self, user, files): data = {"user": user} return self._send_request_with_files( "POST", "/files/upload", data=data, files=files ) ``` For sending files to external platforms, ensure your HTTP request is formatted to handle multipart form-data. Here's an example using cURL: ```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"' ``` Replace `'/path/to/file'` with the actual path to your file and fill in the placeholders like `${props.apiBaseUrl}`, `{dataset_id}`, and `{api_key}` with your specific values. This approach might help you configure your HTTP request node to include file attachments <sup>[[1]](https://github.com/langgenius/dify/issues/16775)</sup>. Regarding the file key, Dify assigns a unique identifier to each uploaded file by generating a UUID and combining it with the current tenant ID and file extension. The file key is constructed as follows: ```python file_uuid = str(uuid.uuid4()) file_key = "upload_files/" + (current_tenant_id or "") + "/" + file_uuid + "." + extension ``` This key is used to save the file in storage and is stored in the database as part of the `UploadFile` record <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/services/file_service.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/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/55bf0135-87bc-4f82-a442-9d71342be48c?feedback_type=other)</sup>
Author
Owner

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

For questions, please use discussion instead.

https://docs.dify.ai/guides/workflow/node/http-request

You can manually add a HTTP node in the workflow, it can accept the file or files in the Start node, you can always to use this node to send file to other platform.

@crazywoola commented on GitHub (Mar 30, 2025): For questions, please use discussion instead. https://docs.dify.ai/guides/workflow/node/http-request You can manually add a HTTP node in the workflow, it can accept the file or files in the Start node, you can always to use this node to send file to other platform.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12332