Skip to content

Commit 6b3dadc

Browse files
beveradbclaude
andcommitted
fix: send multipart encoding when using gcs_uri (fixes 400 error)
FastAPI requires multipart/form-data for endpoints with File()/Form() parameters. When gcs_uri is used without a file upload, requests defaulted to x-www-form-urlencoded, causing a 400 Bad Request. Fix: send a dummy empty file field to force multipart encoding. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ea0e5b commit 6b3dadc

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

audio_separator/remote/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ def separate_audio(
149149

150150
try:
151151
# Increase timeout for large files (5 minutes)
152+
# When using gcs_uri (no file upload), we still need multipart/form-data
153+
# encoding because FastAPI requires it for endpoints with File()/Form() params.
154+
# Passing a dummy empty file field forces requests to use multipart encoding.
155+
if not files:
156+
files = {"file": ("", b"", "application/octet-stream")}
152157
response = self.session.post(
153158
f"{self.api_url}/separate",
154-
files=files if files else None,
159+
files=files,
155160
data=data,
156161
timeout=300,
157162
)

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.44.0"
7+
version = "0.44.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"

tests/unit/test_remote_api_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,10 @@ def test_separate_audio_with_gcs_uri(self, mock_post, api_client):
536536

537537
assert result["task_id"] == "test-task-gcs"
538538

539-
# Verify gcs_uri was sent in form data, no file upload
539+
# Verify gcs_uri was sent in form data
540540
call_args = mock_post.call_args
541-
assert call_args[1]["files"] is None
541+
# A dummy empty file is sent to force multipart encoding (FastAPI requires it)
542+
assert call_args[1]["files"]["file"][0] == "" # empty filename
542543
assert call_args[1]["data"]["gcs_uri"] == "gs://my-bucket/path/to/audio.flac"
543544

544545
def test_separate_audio_requires_file_or_gcs_uri(self, api_client):

0 commit comments

Comments
 (0)