error when launching image library in react-native

Viewed 568

So I am trying to lauch the image library with a package called react-native-image-picker:

function launchLibrary(fun) {

     let options = {
        storageOptions: {
         skipBackup: true,
         path: 'images',
      },
     };

    ImagePicker.launchImageLibrary(options, (response) => {
      console.log('Response = ', response);
      if (response.didCancel) {
        console.log('User cancelled image picker');
      } else if (response.error) {
        console.log('ImagePicker Error: ', response.error);
      } else if (response.customButton) {
        console.log('User tapped custom button: ', response.customButton);
        alert(response.customButton);
      } else {
        const source = { uri: response.uri };
        console.log(source);
        console.log('response', JSON.stringify(response));
        fun(response);
      }
    });
};

Then when the function gets executed, I get the following response:

 response {"errorMessage":"Activity error","errorCode":"others"}

What went wrong here?

2 Answers

The Google Play store no longer accepts builds targeting SDK < 30 so I managed to get it working with a different work around.

I updated react-native-image-picker to version "^4.7.0" and the error went away, but note that launchImageLibrary response may now contain an array of "assets" with image data, rather than including the image data right within the response object.

After updating, replacing response.uri with response.assets[0].uri did the trick for me.

Related