react-native-image-picker not returning data from camera

Viewed 3351

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 Answers

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

Related