4
votes

I'm using react-native-image-picker to load photos. This seems to work well for photos pulled out of the camera roll, but if the user chooses to take a photo, there's no data in the response, just an empty string.

I'm using these options:

{
  title: 'Upload Photo',
  cancelButtonTitle: 'Cancel',
  takePhotoButtonTitle: 'Take Photo...',
  chooseFromLibraryButtonTitle: 'Choose from Library...',
  noData: false,
  mediaType: 'photo',
  quality: 0.2,
}

and launching the image picker with:

UIImagePickerManager.showImagePicker(options, (response) => {
  console.log(response);
});

will work fine for images picked out of the camera roll, but will give me an empty string for response.data when an new image is taken with the camera.

What gives?

1
Are you on iOS or Android?SudoPlz
So far, just on iOS. But I'd like a solution that works on both.nicholas
It works fine for me on iOS .. I've got a problem with Android.SudoPlz
The problem is not as you describe. In android it does get the data and is saved temporarily to sd card. Here the actual problem is react native <image> is not able to load image from sdcard. stackoverflow.com/questions/37878809/…Rajan Twanabashu

1 Answers

0
votes

if you want to show image using data (noData:false) use this:

UIImagePickerManager.showImagePicker(options, 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);
    } else {
        const source = {uri: 'data:image/jpeg;base64,' + response.data};
        this.setState({
            avatarSource: source,
        });
    }
});

and set avatarSource state for image source