Search code examples
androidreact-nativefetchmultipartform-data

Photo upload on React Native Android produce Type Error Network Error


I'm executing a photo upload using the fetch API and I keep receiving Type Error Network Request Error. I receive the same error on the emulator and a device. I'm using react-native-image-crop-picker as the source for the photo upload data. Any thoughts?

const handlePhotoUpload =  async (image: any, token: string) => {

      const { path, filename, mime } = image;

      const uri = path.replace("file://", "")
      const file = {
        uri,            
        type: mime,           
        name: filename             
      };

      const body = new FormData()
      body.append('file', file)

      const config = {
        method: 'POST', 
        headers: { 'Authorization': 'Bearer ' + token },
        body
      };

      return await fetch(`${<API URL>}/user/photo`, config)

}

Solution

  • I faced same issue, it happens in Android, but works well in IOS. I guess this issue about Flipper Network.

    For while, I commented initializeFlipper(this, getReactNativeHost().getReactInstanceManager())

    in this file /android/app/src/main/java/com/{your_project}/MainApplication.java