How to download the file uploaded by the start node through code execution? I see that the parameters passed in only have a temporary address #14752

Closed
opened 2026-02-21 19:18:37 -05:00 by yindo · 3 comments
Owner

Originally created by @a-l-o-n-g on GitHub (Jun 19, 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.4.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I deployed dify through Docker, but due to its inability to recognize scanned PDF files, I am now using code execution nodes to retrieve attachments uploaded by users. I want to use Python packages such as PyMuPDF and pyEsseract to recognize them, so I need to download the file content. However, I have been unable to retrieve the file. What is the solution?

Image

Image

✔️ Expected Behavior

Hope to be able to read the file normally

Actual Behavior

Image

Originally created by @a-l-o-n-g on GitHub (Jun 19, 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.4.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I deployed dify through Docker, but due to its inability to recognize scanned PDF files, I am now using code execution nodes to retrieve attachments uploaded by users. I want to use Python packages such as PyMuPDF and pyEsseract to recognize them, so I need to download the file content. However, I have been unable to retrieve the file. What is the solution? ![Image](https://github.com/user-attachments/assets/3cf66fec-293c-4367-afb7-1a53ea439570) ![Image](https://github.com/user-attachments/assets/29f422a1-7367-46f0-94a8-a6df24d95b51) ### ✔️ Expected Behavior Hope to be able to read the file normally ### ❌ Actual Behavior ![Image](https://github.com/user-attachments/assets/530df25f-56d0-40c5-8817-cf8d886cc1dc)
yindo added the 🙋‍♂️ question label 2026-02-21 19:18:37 -05:00
yindo closed this issue 2026-02-21 19:18:37 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

Dify provides access to files uploaded by the start node using signed, time-limited URLs, which are included in the url field of the file variable's dictionary. In code execution nodes, you only get this URL, not a direct file path or raw bytes, for security reasons.

To process the file (for example, with PyMuPDF or pyTesseract), you need to fetch the file content yourself using Python. Here’s a quick example using the requests library:

import requests

# Suppose 'file_info' is the variable passed to your code node, containing the file metadata
file_url = file_info['url']  # This is the signed, temporary download URL

response = requests.get(file_url)
response.raise_for_status()
file_bytes = response.content

# Now you can use file_bytes with PyMuPDF, pyTesseract, etc.

This pattern is intentional and standard for secure, ephemeral file access in web apps. If you need to process multiple files, loop over the list and fetch each file using its url field.

Reference:

Let me know if you need a more detailed example for your specific use case!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> Dify provides access to files uploaded by the start node using signed, time-limited URLs, which are included in the `url` field of the file variable's dictionary. In code execution nodes, you only get this URL, not a direct file path or raw bytes, for security reasons. To process the file (for example, with PyMuPDF or pyTesseract), you need to fetch the file content yourself using Python. Here’s a quick example using the `requests` library: ```python import requests # Suppose 'file_info' is the variable passed to your code node, containing the file metadata file_url = file_info['url'] # This is the signed, temporary download URL response = requests.get(file_url) response.raise_for_status() file_bytes = response.content # Now you can use file_bytes with PyMuPDF, pyTesseract, etc. ``` This pattern is intentional and standard for secure, ephemeral file access in web apps. If you need to process multiple files, loop over the list and fetch each file using its `url` field. Reference: - [How Dify generates and uses signed URLs for file access](https://github.com/langgenius/dify/blob/d34795fc08383d5de45b7388b89bd4a5af8ad025/api/core/file/models.py) - [How code execution nodes receive file info and what you need to do](https://github.com/langgenius/dify/blob/d34795fc08383d5de45b7388b89bd4a5af8ad025/api/core/workflow/nodes/code/code_node.py) Let me know if you need a more detailed example for your specific use case! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/518157eb-1c36-4d6a-900e-634a098d56a1?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/21269)
Author
Owner

@a-l-o-n-g commented on GitHub (Jun 19, 2025):

@dosu. I tried using requests. get (file_url) but still couldn't read the file
Image

@a-l-o-n-g commented on GitHub (Jun 19, 2025): [@dosu](https://go.dosu.dev/dosubot). I tried using requests. get (file_url) but still couldn't read the file ![Image](https://github.com/user-attachments/assets/84311159-4081-463d-9a1c-97e74d79b5af)
Author
Owner

@dosubot[bot] commented on GitHub (Jun 20, 2025):

The "Invalid URL" error happens because the file URL generated by Dify is missing the scheme (like http:// or https://). This usually means the FILES_URL environment variable in your Docker .env file is not set correctly.

To fix this:

  1. Open your docker/.env file.
  2. Find the FILES_URL setting and make sure it is set to your Dify access address, including the scheme. For example:
    FILES_URL=http://192.168.10.14/
    
    If you use a non-standard port, include it:
    FILES_URL=http://192.168.10.14:5001/
    
  3. Save the file.
  4. Restart your Docker services to apply the change:
    docker-compose down && docker-compose up -d
    
  5. Make sure you use your actual intranet IP (not localhost), and that there are no spaces in the URL. Disable any proxy software during testing.

This should ensure all generated file URLs are valid and accessible in your code node.
References: 1 2 3

If you still see errors, try printing/logging the actual file_url value before using it in requests.get() to confirm its format.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 20, 2025): <!-- Answer --> The "Invalid URL" error happens because the file URL generated by Dify is missing the scheme (like `http://` or `https://`). This usually means the `FILES_URL` environment variable in your Docker `.env` file is not set correctly. To fix this: 1. Open your `docker/.env` file. 2. Find the `FILES_URL` setting and make sure it is set to your Dify access address, including the scheme. For example: ``` FILES_URL=http://192.168.10.14/ ``` If you use a non-standard port, include it: ``` FILES_URL=http://192.168.10.14:5001/ ``` 3. Save the file. 4. Restart your Docker services to apply the change: ``` docker-compose down && docker-compose up -d ``` 5. Make sure you use your actual intranet IP (not `localhost`), and that there are no spaces in the URL. Disable any proxy software during testing. This should ensure all generated file URLs are valid and accessible in your code node. References: [1](https://github.com/langgenius/dify/issues/15847) [2](https://github.com/langgenius/dify/issues/20591) [3](https://github.com/langgenius/dify/issues/17395) If you still see errors, try printing/logging the actual `file_url` value before using it in `requests.get()` to confirm its format. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/cddbde49-762a-42c5-be1d-bdcf09b521e3?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/21269)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14752