There is no way to obtain the file_key or URL of AWS S3 based on the file_id #5918

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

Originally created by @lichao4Java on GitHub (Oct 4, 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).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

{
"event": "message_file",
"conversation_id": "933e723c-d778-4031-b8b2-dca7b85d283c",
"message_id": "b25a3267-ff19-49f9-93c9-3885214f0bf8",
"created_at": 1728088336,
"task_id": "1ce7a88c-48a3-4e91-af60-7d6c0a8c4467",
"id": "1ec851a0-ff78-46af-8516-978e61ba8581",
"type": "image",
"belongs_to": "assistant",
"url": "/files/tools/7690f33c-67f5-4ee2-af01-4d01fb897a6d.png?timestamp=1728088356&nonce=4f58f055ef2383cc9221d41a9f3f96af&sign=rERQEG68XFr-93TSlNG0mRqSKkXeIokSacgooPbX4kM="
}

The URL has a timestamp and will return 403 Invalid request after expiration, How to obtain the latest URL based on file_id through API or other methods?

✔️ Expected Behavior

You can obtain the URL of AWS S3 based on the file_id

image image

The source code is obtained by querying the file_key based on the file_id and then retrieving the file from storage. How can it be obtained through the API? I deployed it using Docker

Actual Behavior

The URL has a timestamp and will return 403 Invalid request after expiration, How to obtain the latest URL based on file_id through API or other methods?

Originally created by @lichao4Java on GitHub (Oct 4, 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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce { "event": "message_file", "conversation_id": "933e723c-d778-4031-b8b2-dca7b85d283c", "message_id": "b25a3267-ff19-49f9-93c9-3885214f0bf8", "created_at": 1728088336, "task_id": "1ce7a88c-48a3-4e91-af60-7d6c0a8c4467", "id": "1ec851a0-ff78-46af-8516-978e61ba8581", "type": "image", "belongs_to": "assistant", "url": "/files/tools/7690f33c-67f5-4ee2-af01-4d01fb897a6d.png?timestamp=1728088356&nonce=4f58f055ef2383cc9221d41a9f3f96af&sign=rERQEG68XFr-93TSlNG0mRqSKkXeIokSacgooPbX4kM=" } The URL has a timestamp and will return 403 Invalid request after expiration, How to obtain the latest URL based on file_id through API or other methods? ### ✔️ Expected Behavior You can obtain the URL of AWS S3 based on the file_id <img width="933" alt="image" src="https://github.com/user-attachments/assets/86f1f689-d895-477b-bdc3-27b6fcb430e0"> <img width="950" alt="image" src="https://github.com/user-attachments/assets/9d9d5d48-f2e5-483d-bb46-8805a4ec7fae"> The source code is obtained by querying the file_key based on the file_id and then retrieving the file from storage. How can it be obtained through the API? I deployed it using Docker ### ❌ Actual Behavior The URL has a timestamp and will return 403 Invalid request after expiration, How to obtain the latest URL based on file_id through API or other methods?
yindo closed this issue 2026-02-21 18:13:14 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 4, 2024):

To obtain the latest URL of an AWS S3 file based on the file_id, you can use the get_signed_temp_image_url method from the UploadFileParser class. This method generates a signed temporary URL for the file, which includes a timestamp and a signature to ensure secure access. Here's how you can use it:

signed_url = UploadFileParser.get_signed_temp_image_url(upload_file_id)

This method constructs a URL with a timestamp, nonce, and a signature, which is valid for a limited time as defined by dify_config.FILES_ACCESS_TIMEOUT. If the URL returns a 403 Invalid request after expiration, you will need to generate a new signed URL using the same method [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 4, 2024): <!-- Answer --> To obtain the latest URL of an AWS S3 file based on the `file_id`, you can use the `get_signed_temp_image_url` method from the `UploadFileParser` class. This method generates a signed temporary URL for the file, which includes a timestamp and a signature to ensure secure access. Here's how you can use it: ```python signed_url = UploadFileParser.get_signed_temp_image_url(upload_file_id) ``` This method constructs a URL with a timestamp, nonce, and a signature, which is valid for a limited time as defined by `dify_config.FILES_ACCESS_TIMEOUT`. If the URL returns a 403 Invalid request after expiration, you will need to generate a new signed URL using the same method <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/file/upload_file_parser.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@lichao4Java commented on GitHub (Oct 4, 2024):

How can it be obtained through the API? I deployed it using Docker

@lichao4Java commented on GitHub (Oct 4, 2024): How can it be obtained through the API? I deployed it using Docker
Author
Owner

@dosubot[bot] commented on GitHub (Oct 4, 2024):

To obtain the latest URL of a file based on the file_id through the API in a Docker deployment, you can use the API endpoint that constructs a signed temporary URL. This is done using the get_signed_temp_image_url method from the UploadFileParser class. This method generates a URL with a timestamp, nonce, and signature, which is valid for a limited time.

Here's a brief overview of how you can achieve this:

  1. API Endpoint: The endpoint is constructed using the base URL from dify_config.FILES_URL and appending /files/{upload_file_id}/image-preview.

  2. Generate Signed URL: Use the get_signed_temp_image_url method to generate a new signed URL whenever needed. This method ensures the URL is valid only for a limited time.

  3. Security: The URL includes query parameters for timestamp, nonce, and sign, which are used for security purposes to verify the request.

If you need to automate this process, you can create a script or service that calls this method to generate a new URL whenever the previous one expires [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 4, 2024): <!-- Answer --> To obtain the latest URL of a file based on the `file_id` through the API in a Docker deployment, you can use the API endpoint that constructs a signed temporary URL. This is done using the `get_signed_temp_image_url` method from the `UploadFileParser` class. This method generates a URL with a timestamp, nonce, and signature, which is valid for a limited time. Here's a brief overview of how you can achieve this: 1. **API Endpoint**: The endpoint is constructed using the base URL from `dify_config.FILES_URL` and appending `/files/{upload_file_id}/image-preview`. 2. **Generate Signed URL**: Use the `get_signed_temp_image_url` method to generate a new signed URL whenever needed. This method ensures the URL is valid only for a limited time. 3. **Security**: The URL includes query parameters for `timestamp`, `nonce`, and `sign`, which are used for security purposes to verify the request. If you need to automate this process, you can create a script or service that calls this method to generate a new URL whenever the previous one expires <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/file/upload_file_parser.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5918