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:
Using StreamingResponse instead of FileResponse for better header control
Implementing proper UTF-8 encoding for filenames in Content-Disposition headers
Adding proper MIME type detection for downloaded files
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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/7831
Author: @juananpe
Created: 12/13/2024
Status: ❌ Closed
Base:
dev← Head:fixunicodedownloadcitations📝 Commits (1)
3485beafix: 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
devbranch.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:
Changes
urllib.parse.quotefilenameand RFC 5987filename*parameters for better browser compatibility🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.