Skip to content

Commit

Permalink
Fix filename form data on uploads
Browse files Browse the repository at this point in the history
fixes: pulp#842
  • Loading branch information
gerrod3 committed Dec 6, 2023
1 parent e694dd7 commit afaa391
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/842.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug where the filenames on uploads were not being sent.
13 changes: 7 additions & 6 deletions pulp-glue/pulp_glue/common/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,20 +504,21 @@ def render_request_body(
elif content_type.startswith("application/x-www-form-urlencoded"):
data = body
elif content_type.startswith("multipart/form-data"):
uploads: Dict[str, UploadType] = {}
uploads: Dict[str, Tuple[str, UploadType, str]] = {}
data = {}
# Extract and prepare the files to upload
if body:
for key, value in body.items():
if isinstance(value, (bytes, BufferedReader)):
uploads[key] = value
uploads[key] = (
getattr(value, "name", key),
value,
"application/octet-stream",
)
else:
data[key] = value
if uploads:
files = [
(key, (key, file_data, "application/octet-stream"))
for key, file_data in uploads.items()
]
files = [(key, upload_data) for key, upload_data in uploads.items()]
break
else:
# No known content-type left
Expand Down

0 comments on commit afaa391

Please sign in to comment.