Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native 0.62.0 - Network request error on Android for file upload

I have upgraded react-native to 0.62 and i got the problem of Network error for Android only, iOS works fine.

I use FormData object to populate data formated as

const data = new FormData(); 
// On Android i add file protocol to file path - file://... 
data.append('photos', { 
   uri: 'file:///data/.../my-image.jpeg', 
   type: 'image/jpeg',
   name: 'my-image.jpeg' 
});

and other textual data

data.append('description', 'my long description...');

Does anyone have the problem?

I have tried multiple Android SDKs 27, 28, 29, and got same problem on all :(

The things is if i do not upload images, but only textual data request works just fine :(

Any suggestion welcome :)?

like image 770
Kristijan Tomic Avatar asked Jun 22 '26 03:06

Kristijan Tomic


1 Answers

It is happening because of Flipper network plugin. Comment line number 43 in the file android/app/src/debug/java/com/<yourappname>/ReactNativeFlipper.java

38      NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39      NetworkingModule.setCustomClientBuilder(
40          new NetworkingModule.CustomClientBuilder() {
41            @Override
42            public void apply(OkHttpClient.Builder builder) {
43      //        builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44            }
45          });
46      client.addPlugin(networkFlipperPlugin);
like image 79
Krishan Kumar Mourya Avatar answered Jun 24 '26 17:06

Krishan Kumar Mourya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!