fix(go): use field name as filename in multipart uploads#11819
Closed
developerkunal wants to merge 3 commits intofern-api:mainfrom
Closed
fix(go): use field name as filename in multipart uploads#11819developerkunal wants to merge 3 commits intofern-api:mainfrom
developerkunal wants to merge 3 commits intofern-api:mainfrom
Conversation
When io.Reader doesn't implement Name() (e.g., bytes.Reader, strings.Reader), use the field name as the default filename in Content-Disposition header. This ensures the filename attribute is always present in multipart/form-data uploads, fixing compatibility with APIs that require this attribute. Aligns with behavior in TypeScript and Python generators: - TypeScript: Native FormData API auto-fills default when filename is undefined - Python: httpx/requests auto-fills default when filename is None - Go: Now uses field name as fallback since stdlib doesn't auto-fill Changes: - Modified writeFile() to use field name when filename is empty - Added tests for strings.Reader, bytes.Reader, and bytes.Buffer - Verifies Content-Disposition header includes filename attribute
There was a problem hiding this comment.
Pull request overview
Fixes Go SDK generator multipart file uploads for in-memory io.Reader inputs (e.g., bytes.Reader, strings.Reader, bytes.Buffer) by ensuring a filename is always set in the multipart part’s Content-Disposition.
Changes:
- Add a fallback filename (use the multipart field name) when the provided file reader has no filename.
- Add unit tests covering unnamed in-memory readers and validating
Content-Dispositionincludesfilename=.... - Bump Go SDK versions changelog with a fix entry describing the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| generators/go/sdk/versions.yml | Adds a 1.23.4 changelog entry documenting the multipart filename fallback fix. |
| generators/go/internal/generator/sdk/internal/multipart.go | Implements filename fallback to the field name when getFilename(file) returns empty. |
| generators/go/internal/generator/sdk/internal/multipart_test.go | Adds tests for unnamed in-memory readers and asserts the Content-Disposition header includes a filename attribute. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4f95d2a to
f0b071e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug in the Go SDK generator where multipart file uploads fail when using in-memory readers (
bytes.Reader,strings.Reader,bytes.Buffer) that don't have a filename. The generated multipart writer now uses the field name as the filename when no filename is provided, ensuring the Content-Disposition header includes the requiredfilenameattribute.This aligns with how TypeScript and Python generators handle unnamed file uploads (FormData auto-fills in JS, httpx/requests auto-fills in Python).
Changes Made
writeFile()ingenerators/go/internal/generator/sdk/internal/multipart.goto use field name as filename fallbackstrings.Reader,bytes.Reader, andbytes.BufferTesting