fix: httpx 0.28 AsyncClient multipart compat — pass all fields via files= list
All checks were successful
Deploy / deploy (push) Successful in 15s
All checks were successful
Deploy / deploy (push) Successful in 15s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -116,23 +116,26 @@ class PaperlessClient:
|
||||
self, file_bytes: bytes, filename: str, metadata: dict
|
||||
) -> str:
|
||||
"""Upload a document; returns the Celery task_id UUID string."""
|
||||
form: list[tuple[str, str]] = []
|
||||
# Build multipart as a list of tuples so all parts go through a single
|
||||
# AsyncByteStream — required for httpx >= 0.28 with AsyncClient.
|
||||
parts: list[tuple[str, tuple]] = [
|
||||
("document", (filename, file_bytes, "application/octet-stream")),
|
||||
]
|
||||
for key in ("title", "created", "archive_serial_number"):
|
||||
val = metadata.get(key)
|
||||
if val is not None:
|
||||
form.append((key, str(val)))
|
||||
parts.append((key, (None, str(val), "text/plain")))
|
||||
if metadata.get("correspondent") is not None:
|
||||
form.append(("correspondent", str(metadata["correspondent"])))
|
||||
parts.append(("correspondent", (None, str(metadata["correspondent"]), "text/plain")))
|
||||
if metadata.get("document_type") is not None:
|
||||
form.append(("document_type", str(metadata["document_type"])))
|
||||
parts.append(("document_type", (None, str(metadata["document_type"]), "text/plain")))
|
||||
for tag_id in metadata.get("tags", []):
|
||||
form.append(("tags", str(tag_id)))
|
||||
parts.append(("tags", (None, str(tag_id), "text/plain")))
|
||||
|
||||
r = await self._request(
|
||||
"POST",
|
||||
"/api/documents/post_document/",
|
||||
files={"document": (filename, file_bytes, "application/octet-stream")},
|
||||
data=form,
|
||||
files=parts,
|
||||
)
|
||||
result = r.json()
|
||||
# API returns a plain task UUID string
|
||||
|
||||
Reference in New Issue
Block a user