Skip to content

fix(go): use field name as filename in multipart uploads#11819

Closed
developerkunal wants to merge 3 commits intofern-api:mainfrom
developerkunal:kunal/fix-go-multipart-filename
Closed

fix(go): use field name as filename in multipart uploads#11819
developerkunal wants to merge 3 commits intofern-api:mainfrom
developerkunal:kunal/fix-go-multipart-filename

Conversation

@developerkunal
Copy link
Copy Markdown
Contributor

@developerkunal developerkunal commented Jan 27, 2026

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 required filename attribute.

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

  • Modified writeFile() in generators/go/internal/generator/sdk/internal/multipart.go to use field name as filename fallback
  • Added comprehensive unit tests for strings.Reader, bytes.Reader, and bytes.Buffer
  • Added Content-Disposition header validation in tests
  • Updated README.md generator (if applicable)

Testing

  • Unit tests added/updated
  • Manual testing completed

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
Copilot AI review requested due to automatic review settings January 27, 2026 16:08
@developerkunal developerkunal changed the title fix(go): support in-memory readers in multipart file uploads fix(go): use field name as filename in multipart uploads Jan 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-Disposition includes filename=....
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants