Skip to content

Fix wrong encode for bytes in HttpPart for multipart/form-data#4345

Merged
iscai-msft merged 1 commit into
Azure:release/april-2026from
iscai-msft:publish/tcgc-multipart-bytes-fix
Apr 28, 2026
Merged

Fix wrong encode for bytes in HttpPart for multipart/form-data#4345
iscai-msft merged 1 commit into
Azure:release/april-2026from
iscai-msft:publish/tcgc-multipart-bytes-fix

Conversation

@iscai-msft
Copy link
Copy Markdown
Contributor

No description provided.

…zure#4317)

`bytes` in `HttpPart<bytes>` for `multipart/form-data` was incorrectly
encoded as `base64` instead of `bytes`.

In `addMultipartPropertiesToModelType`, the property type is replaced
with the part body type via `getClientTypeWithDiagnostics`. For `bytes`,
this creates the `SdkBuiltInType` through the `Scalar` path in
`addEncodeInfo` with no `defaultContentType`, which unconditionally
defaults to `base64`. The part's actual content type
(`application/octet-stream`) was never consulted.

### Changes
- **`packages/typespec-client-generator-core/src/types.ts`** — Re-apply
`addEncodeInfo` after the type replacement, passing the part's default
content type so the existing content-type-aware branching
(`!isMediaTypeJson && !isMediaTypeXml && !isMediaTypeTextPlain →
"bytes"`) takes effect.
-
**`packages/typespec-client-generator-core/test/types/multipart.test.ts`**
— Added encode assertions to existing test and a new test for the
anonymous model repro case.

```typespec
op upload(
  @Header contentType: "multipart/form-data",
  @multipartBody body: {
    profileImage: HttpPart<bytes>;  // encode is now "bytes", was "base64"
  },
): NoContentResponse;
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Apr 28, 2026
@iscai-msft iscai-msft enabled auto-merge (squash) April 28, 2026 20:52
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 28, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-azure-core@4345
npm i https://pkg.pr.new/@azure-tools/typespec-azure-resource-manager@4345
npm i https://pkg.pr.new/@azure-tools/typespec-client-generator-core@4345

commit: 17eb401

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

@iscai-msft iscai-msft merged commit 656ea39 into Azure:release/april-2026 Apr 28, 2026
34 of 37 checks passed
tadelesh added a commit that referenced this pull request Apr 29, 2026
…0.67.4 (#4349)

Hotfix version bump for TCGC 0.67.4 from release/april-2026 branch.

Fix: #4345 - Fix wrong encode for bytes in HttpPart for
multipart/form-data

Co-authored-by: tadelesh <chenjieshi@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants