A framework for building native applications using React
Fix (android): show payload preview for FormData and one-shot uploads in DevTools (#55764) (#56742)
Summary: Follow-up to https://github.com/facebook/react-native/issues/56406. After that PR landed, NetworkEventUtil.getRequestBodyPreview still returns the literal string "[Preview unavailable]" in two cases: The top-level RequestBody.isOneShot() is true (e.g. a single URI/file upload). The body is a MultipartBody whose parts include any one-shot stream (the common case for FormData with files on Android). Both branches exist for a good reason — calling writeTo() on a one-shot stream would drain it and break the real upload. This PR keeps that invariant but replaces the two return sites with structured previews: Single one-shot body → [Binary data, N bytes] (or [Binary data] if contentLength() is unknown). MultipartBody with one-shot parts → a multipart envelope using the request's actual boundary, with text parts inlined and one-shot parts replaced by [Binary data, N bytes]. The result parses cleanly against the on-the-wire Content-Type: multipart/form-data; boundary=..., so DevTools renders it the same way it renders any other multipart payload. Net result: issue https://github.com/facebook/react-native/issues/55764 (no payload preview for FormData / file uploads in the React Native DevTools Network tab) is closed, with no change to what gets sent on the wire. ## Changelog: NetworkEventUtil.kt: replace the two "[Preview unavailable]" returns with binaryPartLabel(body) and a new previewMultipartWithBinaryParts(body) helper. No change to the existing all-text path. NetworkEventUtilTest.kt: 6 new tests covering null body, plain string body, ProgressRequestBody unwrapping, multipart with text parts, multipart with a file part, and a single one-shot body. [ANDROID] [FIXED] - Show request body preview for FormData and file uploads in DevTools Network tab Pull Request resolved: https://github.com/facebook/react-native/pull/56742 Test Plan: 1) `` ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.modules.network.*"`` — 16/16 pass in NetworkEventUtilTest, full network suite green. 2) Manual: in RN-Tester debug build, POST a FormData with a file using fetch → DevTools Network → Payload tab now shows the multipart envelope with [Binary data, N bytes] instead of [Preview unavailable]. 3) Manual: POST a single-file RequestBody from a URI → preview now shows [Binary data, N bytes]. Stream safety The whole point of https://github.com/facebook/react-native/issues/56406's bail-outs was to avoid draining one-shot streams. This PR preserves that: it never calls writeTo() on a body whose isOneShot() is true. The only RequestBody methods invoked on one-shot bodies are contentType() and contentLength(), both of which are pure getters per the OkHttp docs. Refs https://github.com/facebook/react-native/issues/55764, follows up on https://github.com/facebook/react-native/issues/56406. Reviewed By: javache Differential Revision: D105997964 Pulled By: huntie fbshipit-source-id: e1ac0091cd167d8118bd0952b5bd9829f9ec85a5
H
HarshitMadhav committed
48fe6df3d2b2d72138bda212354443c22c60302f
Parent: 09fc043
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com>
on 5/23/2026, 9:38:56 AM