fix: JSON-encode object fields in multipart request bodies - #337
Merged
Conversation
Channel uploads sent `user` as the literal string "[object Object]", which the API rejects with `bad user id`, and fields with no value went out as the string "undefined". Encode form fields in ApiClient so every multipart endpoint is covered, rather than only the two global upload methods StreamClient was hand-patching.
szuperaz
approved these changes
Aug 21, 2026
oliverlaz
pushed a commit
that referenced
this pull request
Aug 21, 2026
🤖 I have created a release *beep* *boop* --- ## [0.8.2](v0.8.1...v0.8.2) (2026-08-21) ### Features * feed counts endpoint ([#335](#335)) ([cd55e36](cd55e36)) ### Bug Fixes * JSON-encode object fields in multipart request bodies ([#337](#337)) ([5ed3f5b](5ed3f5b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
ApiClientbuilt its multipart body with a bareFormData.append(key, value), so any non-file field was coerced byString(). AFilesurvives that, an object does not.StreamClient.uploadFile/uploadImageworked around it by hand-stringifyinguserandupload_sizesbehind@ts-expect-error. The channel-scoped uploads —chat.uploadChannelFile,chat.uploadChannelImage,channel.uploadChannelFile,channel.uploadChannelImage— had no such wrapper and were broken outright. Verified against the API:That's the server reading
"[object Object]"as the user id.Encoding now lives in
ApiClient.multipartBodyStringify: files pass through asBlobs, scalars keep their existing coercion, objects and arrays getJSON.stringify, and no-value fields are dropped instead of being sent as the string"undefined"(which the patched global path was also doing). With one encoding site theStreamClientworkarounds are redundant and were removed; the overrides stay because the spec still typesfileasstring.Testing
New
__tests__/multipart.test.tsasserts on theFormDatathat actually reachesfetch— object/array/file/scalar/no-value fields, no double-encoding of pre-encoded strings, plus all four upload entry points. Runs in CI without credentials. Each new-behavior test was confirmed to fail before the fix.Also added a channel-upload suite to
__tests__/file-uploads.test.ts, which had no coverage — this is why the bug shipped. Both suites in that file staydescribe.skipper the existing convention there; run live, all 4 pass with the fix and the 2 channel tests fail without it.