[PR #7831] [CLOSED] fix: handle Unicode filenames in file download response #45165

Closed
opened 2026-04-29 19:29:24 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/7831
Author: @juananpe
Created: 12/13/2024
Status: Closed

Base: devHead: fixunicodedownloadcitations


📝 Commits (1)

  • 3485bea fix: handle Unicode filenames in file download response

📊 Changes

1 file changed (+54 additions, -29 deletions)

View changed files

📝 backend/open_webui/apps/webui/routers/files.py (+54 -29)

📄 Description

Pull Request Checklist

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:

Description

The file download endpoint was failing with a 400 error when trying to download files with non-ASCII characters in their filenames (like accented characters). This was due to FastAPI/Starlette attempting to encode the Content-Disposition header using latin-1 encoding.

Additionally, the implementation now properly handles both physical files and text content fallbacks with consistent filename encoding.

This PR fixes the issue by:

  1. Using StreamingResponse instead of FileResponse for better header control
  2. Implementing proper UTF-8 encoding for filenames in Content-Disposition headers
  3. Adding proper MIME type detection for downloaded files
  4. Maintaining the text content fallback functionality with proper encoding

Changes

  • Replaced FileResponse with StreamingResponse in the file download endpoint
  • Added proper filename encoding using urllib.parse.quote
  • Implemented file streaming with chunks for better memory efficiency
  • Added MIME type detection for proper Content-Type headers
  • Added both standard filename and RFC 5987 filename* parameters for better browser compatibility
  • Preserved and enhanced the text content fallback functionality

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/7831 **Author:** [@juananpe](https://github.com/juananpe) **Created:** 12/13/2024 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fixunicodedownloadcitations` --- ### 📝 Commits (1) - [`3485bea`](https://github.com/open-webui/open-webui/commit/3485bea60f0630e52587d7c41c35e4cb4c70cc3d) fix: handle Unicode filenames in file download response ### 📊 Changes **1 file changed** (+54 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/apps/webui/routers/files.py` (+54 -29) </details> ### 📄 Description # Pull Request Checklist - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: ## Description The file download endpoint was failing with a 400 error when trying to download files with non-ASCII characters in their filenames (like accented characters). This was due to FastAPI/Starlette attempting to encode the Content-Disposition header using latin-1 encoding. Additionally, the implementation now properly handles both physical files and text content fallbacks with consistent filename encoding. This PR fixes the issue by: 1. Using StreamingResponse instead of FileResponse for better header control 2. Implementing proper UTF-8 encoding for filenames in Content-Disposition headers 3. Adding proper MIME type detection for downloaded files 4. Maintaining the text content fallback functionality with proper encoding ## Changes - Replaced FileResponse with StreamingResponse in the file download endpoint - Added proper filename encoding using `urllib.parse.quote` - Implemented file streaming with chunks for better memory efficiency - Added MIME type detection for proper Content-Type headers - Added both standard `filename` and RFC 5987 `filename*` parameters for better browser compatibility - Preserved and enhanced the text content fallback functionality --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 19:29:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#45165