Skip to content

Conversation

@KeremTurgutlu
Copy link

@KeremTurgutlu KeremTurgutlu commented Nov 29, 2025

Multipart file uploads use streaming bodies in httpx, so r.content raises RequestNotRead unless r.read() is called first to load the content into memory.

Additionally, httpx generates a random 32-character hex boundary for each multipart request, causing identical requests to produce different cache keys. We now normalize multipart content by replacing the boundary with a fixed value before hashing.

Changes:

  • Call r.read() (which is no-op for byte content) before accessing r.content in _key()
  • Add normalize_multipart() to replace random boundaries with a deterministic string

Example requests:

from httpx import post
from pathlib import Path

# Prepare the file
files = [("file", ('some_path', b'some text', "text/plain"))]

# Prepare form data
data = {"model": "some-model", "prompt": "transcribe this"}

# Make the request
r = post("https://example.com/upload", files=files, data=data, timeout=None)

# An example request object with files:
req = httpx.Request( "POST", "https://example.com/upload", files=files, data=data)

@KeremTurgutlu KeremTurgutlu requested a review from comhar November 29, 2025 13:34
@KeremTurgutlu KeremTurgutlu changed the title add-multipart-support Multipart file support Nov 29, 2025
@comhar comhar closed this in #10 Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants