Skip to content

[swift6] Send raw Data multipart parts as files - #25191

Merged
4brunu merged 1 commit into
OpenAPITools:masterfrom
spigo:swift6-fix-multipart-data-filename
Oct 9, 2026
Merged

4brunu merged 1 commit into
OpenAPITools:masterfrom
spigo:swift6-fix-multipart-data-filename

Conversation

@spigo

@spigo spigo commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Part of #21444; complements #22456.

A raw Data multipart value was appended with only a name, so servers expecting a file upload (a part with a filename, e.g. $_FILES in PHP or MultipartFile in Spring) didn't receive a file. Data parts now get filename (the parameter name) and Content-Type: application/octet-stream:

  • alamofire: mpForm.append(data, withName: k, fileName: k, mimeType: "application/octet-stream")
  • urlsession: configureDataUploadRequest takes optional fileName/mimeType, passed only for Data values

String, number and UUID values stay plain form fields. URL values keep their existing file handling.

Verified with the generated default (urlsession) sample by capturing the request body through an OpenAPIInterceptor: the body for ["file": Data(...), "note": "hello"] now contains name="file"; filename="file" with Content-Type: application/octet-stream, and name="note" unchanged. The alamofire variant has been running in a downstream client against a PHP backend. The default and alamofireLibrary samples build.

Note: until #22456 lands, generated API methods still base64-encode Data form params before they reach the builder (via asParameter). This change takes effect for every raw Data value that reaches the builder, and for all of them once #22456 is merged.

PR checklist


Summary by cubic

Raw Data multipart values were sent as plain form fields, so servers expecting a file upload (a part with a filename) didn't receive one. Data parts now include filename (the parameter name) and Content-Type: application/octet-stream in both the alamofire and urlsession libraries, while String, number, and UUID values stay plain form fields.

Written for commit ef8ec9b. Summary will update on new commits.

View guided diff

The alamofire and urlsession libraries appended a raw Data multipart value
with only a name, so servers expecting a file upload (a part with a filename)
didn't receive one. Add filename (the parameter name) and
Content-Type: application/octet-stream to Data parts; String, number and UUID
values stay plain form fields. Update swift6 samples.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 15 files

View guided diff | Re-trigger cubic

@4brunu
4brunu merged commit 4bcba9c into OpenAPITools:master Oct 9, 2026
30 of 31 checks passed
@spigo
spigo deleted the swift6-fix-multipart-data-filename branch October 9, 2026 10:31
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