Skip to content

Commit 8b193be

Browse files
beveradbclaude
andauthored
fix: RFC 5987 encoding for Unicode filenames in Content-Disposition header (#257)
* fix: RFC 5987 encoding for Unicode filenames in Content-Disposition header Fixes download failures for songs with non-ASCII characters (Vietnamese, Japanese, Korean, etc.) by properly encoding the Content-Disposition header. The issue occurred when downloading separated audio files with Unicode filenames like "Việt Nhân - Sầu Thương_(Vocals).flac" - the HTTP header encoding failed with "'latin-1' codec can't encode character". Solution: - Add ASCII fallback filename for older clients - Add RFC 5987 filename*=UTF-8'' parameter for modern clients - Both parameters in the header ensure broad compatibility Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: bump version to 0.41.1 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 76141c8 commit 8b193be

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

audio_separator/remote/deploy_modal.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from importlib.metadata import version
3232
import typing
3333
from typing import Optional
34+
from urllib.parse import quote
3435

3536
# Third-party imports
3637
from fastapi import FastAPI, File, Form, HTTPException, Response, UploadFile
@@ -712,7 +713,13 @@ async def download_file(task_id: str, file_hash: str) -> Response:
712713
print(f"WARNING: Could not detect MIME type for {actual_filename}, using generic type")
713714
content_type = "application/octet-stream"
714715

715-
return Response(content=file_data, media_type=content_type, headers={"Content-Disposition": f"attachment; filename={actual_filename}"})
716+
# RFC 5987 encoding for Unicode filenames in Content-Disposition header
717+
# Provide ASCII fallback for older clients, and UTF-8 encoded filename for modern clients
718+
ascii_filename = "".join(c if ord(c) < 128 else "_" for c in actual_filename)
719+
encoded_filename = quote(actual_filename, safe="")
720+
content_disposition = f"attachment; filename=\"{ascii_filename}\"; filename*=UTF-8''{encoded_filename}"
721+
722+
return Response(content=file_data, media_type=content_type, headers={"Content-Disposition": content_disposition})
716723

717724
except FileNotFoundError as exc:
718725
raise HTTPException(status_code=404, detail="File not found") from exc

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "audio-separator"
7-
version = "0.41.0"
7+
version = "0.41.1"
88
description = "Easy to use audio stem separation, using various models from UVR trained primarily by @Anjok07"
99
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
1010
license = "MIT"

0 commit comments

Comments
 (0)