question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

launchImageLibrary issue for pickup file in Android

See original GitHub issue

react-native-image-picker facing issue in launchImageLibrary for uploading an image to server throw error Network request failed in iOS it’s working fine it happens in Android

  • Tried below all solutions but not working

    1. uesCleartextTraffic=“true” to the AndroidManifest.xml file found inside the dir android/app/src/main/AndroidManifest.xml
    2. Commented this line // initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
      in this file /android/app/src/main/java/com/{your_project}/MainApplication.java
    3. Commented this line // builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); in his file android/app/src/debug/java/com/{your_project}/ReactNativeFlipper.java
    4. Updating FLIPPER version to FLIPPER_VERSION=0.82.0
    5. React native version "react-native": "0.63.3"
  • launchImageLibrary method options

        let options = {
            title: 'Update Profile'
            allowsEditing: false,
            quality: 1,
            noData: true,
            mediaType: "photo",
            saveToPhotos:true,
            storageOptions: {
                skipBackup: true,
                cameraRoll: false
            },
        };

  launchImageLibrary(options, (response) => {
       const mediaPath = Platform.OS == "android" ? { uri: response.uri } : response.uri;
  
                  if (response.didCancel) {
                      console.log('User cancelled photo picker');
                  }
                  else if (response.error) {
                      console.log('ImagePicker Error: ', response.error);
                  }
                  else {
                       setUserProfile(mediaPath)
                  }
              });
  • API call Method
     let formDataRequest = new FormData()
        formDataRequest.append("image",  { uri: response.uri, name: 'fileName;, type: 'image/jpg'})
     
        Api.updateProfileMedia(formDataRequest)
              .then(jsonResponse => {
         if (jsonResponse.status == true || jsonResponse.status == "true") {
    
        }else{
          }
        }) .catch(error => {
          console.log("Error",error);
        })
    

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
dhananjay23commented, Apr 28, 2021

@Johan-dutoit Yes you are right but the concern is Result object provides by the library throws network request exceptions.

1reaction
frenbergcommented, Apr 27, 2021

@dhananjay23 maybe a long shot, but you don’t happen to have “network inspection” active in react-native-debugger? Then uploads usually fails for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-image-picker not working in android 10
Adding the android:requestLegacyExternalStorage="true" in AndroidMenifest.xml file was worked for Android 10. Added it as property of the ...
Read more >
How to pick images from Camera & Gallery in React Native app
In this post, you learned how to implement React Native Image Picker in your React Native app and pick the images from Camera...
Read more >
React Native Pick Images From Camera & Gallery Example
Picking images is an essential task, learn how to pick images from the device's Camera and Gallery in React Native application.
Read more >
Example of Image Picker in React Native
Image Picker in React Native using ImagePicker component with options 1. Take Image, 2. Choose From Library, 3. Choose from Custom Options.
Read more >
ImagePicker - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... File size of the picked image or video, in bytes. height, number, Height...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found