fix history message list file_preview sign_url:if as_attachment is in the url, add it to the sign_url #13434

Closed
opened 2026-02-21 19:12:09 -05:00 by yindo · 1 comment
Owner

Originally created by @sondin on GitHub (Apr 27, 2025).

Originally assigned to: @laipz8200 on GitHub.

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

main

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

When handling files or preview URLs recorded in the history, the re_sign_file_url_answer method fails to preserve the as_attachment parameter, resulting in downloaded files missing their original file extensions.

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @sondin on GitHub (Apr 27, 2025). Originally assigned to: @laipz8200 on GitHub. ### 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 main ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce When handling files or preview URLs recorded in the history, the re_sign_file_url_answer method fails to preserve the as_attachment parameter, resulting in downloaded files missing their original file extensions. ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 19:12:09 -05:00
yindo closed this issue 2026-02-21 19:12:09 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 27, 2025):

To address the issue of preserving the as_attachment parameter in the re_sign_file_url_answer method, you need to modify the method to ensure that this parameter is included in the signed URL. Here's a general approach you can take:

  1. Extract the as_attachment Parameter: Before generating the signed URL, check if the as_attachment parameter is present in the original URL.

  2. Include the Parameter in the Signed URL: When constructing the signed URL, append the as_attachment parameter to the URL if it was present in the original URL.

  3. Modify the URL Signing Logic: Ensure that the logic for signing the URL accommodates additional parameters like as_attachment.

Here's a conceptual example of how you might implement this:

def re_sign_file_url_answer(answer):
    # Extract URLs from the answer
    urls = extract_urls(answer)
    signed_urls = []

    for url in urls:
        # Check for the as_attachment parameter
        as_attachment = 'as_attachment=true' if 'as_attachment=true' in url else ''
        
        # Generate the signed URL
        signed_url = file_helpers.get_signed_file_url(url)
        
        # Append the as_attachment parameter if it exists
        if as_attachment:
            signed_url += f"&{as_attachment}"
        
        signed_urls.append(signed_url)
    
    # Replace original URLs with signed URLs in the answer
    for original_url, signed_url in zip(urls, signed_urls):
        answer = answer.replace(original_url, signed_url)
    
    return answer

This example assumes you have a function extract_urls to get URLs from the answer and a function file_helpers.get_signed_file_url to generate signed URLs. Adjust the implementation based on your actual code structure and logic.

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 (Apr 27, 2025): <!-- Answer --> To address the issue of preserving the `as_attachment` parameter in the `re_sign_file_url_answer` method, you need to modify the method to ensure that this parameter is included in the signed URL. Here's a general approach you can take: 1. **Extract the `as_attachment` Parameter**: Before generating the signed URL, check if the `as_attachment` parameter is present in the original URL. 2. **Include the Parameter in the Signed URL**: When constructing the signed URL, append the `as_attachment` parameter to the URL if it was present in the original URL. 3. **Modify the URL Signing Logic**: Ensure that the logic for signing the URL accommodates additional parameters like `as_attachment`. Here's a conceptual example of how you might implement this: ```python def re_sign_file_url_answer(answer): # Extract URLs from the answer urls = extract_urls(answer) signed_urls = [] for url in urls: # Check for the as_attachment parameter as_attachment = 'as_attachment=true' if 'as_attachment=true' in url else '' # Generate the signed URL signed_url = file_helpers.get_signed_file_url(url) # Append the as_attachment parameter if it exists if as_attachment: signed_url += f"&{as_attachment}" signed_urls.append(signed_url) # Replace original URLs with signed URLs in the answer for original_url, signed_url in zip(urls, signed_urls): answer = answer.replace(original_url, signed_url) return answer ``` This example assumes you have a function `extract_urls` to get URLs from the answer and a function `file_helpers.get_signed_file_url` to generate signed URLs. Adjust the implementation based on your actual code structure and logic. <!-- 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/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d5ac4f2e-0a8b-424c-95aa-1163a9ccc971?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#13434