fix: formData upload broken in debug builds (#56406)

Summary:
So  the formData Upload in fetch is broken on 0.85 on main.
I tracked down this PR https://github.com/facebook/react-native/pull/55456
Also reported here https://github.com/facebook/react-native/issues/56404
RCA:-
```
body.isOneShot()
body.writeTo(buffer)  // This is  draining inner file InputStreams
```
Fix is to walk to each children of multipart and check for Oneshot
## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[ANDROID][FIXED] - FormData uploads broken in debug builds

Pull Request resolved: https://github.com/facebook/react-native/pull/56406

Test Plan:
Tested on RN tester
<img width="416" height="600" alt="image" src="https://github.com/user-attachments/assets/20cae662-e2ba-4fc7-9f8d-d8e365eb95b2" />

Reviewed By: fabriziocucci, huntie

Differential Revision: D100258994

Pulled By: alanleedev

fbshipit-source-id: aeda47d45db2152027598c949f0e602a586c4cb3
This commit is contained in:
riteshshukla04 authored and React Native Bot committed 2026-04-13 03:23:28 +00:00
1 parent 76cf797f17
commit 9dfd26eaaf
2 files changed
+10

No files matched your search

@@ -19,6 +19,7 @@ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
import java.io.IOException
import java.net.SocketTimeoutException
import okhttp3.Headers
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okio.Buffer
@@ -263,6 +264,13 @@ internal object NetworkEventUtil {
return "[Preview unavailable]"
}
// MultipartBody does not propagate isOneShot() from its parts, so check each
// part explicitly. Reading a one-shot part here would drain the underlying
// stream and cause the real request to fail.
if (body is MultipartBody && body.parts().any { it.body().isOneShot() }) {
return "[Preview unavailable]"
}
return try {
val buffer = Buffer()
body.writeTo(buffer)
@@ -146,6 +146,8 @@ internal object RequestBodyUtil {
}
}
override fun isOneShot(): Boolean = true
@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {
var source: Source? = null