0

I am trying to upload image using expo image picker but when click button and select image it gives unhandled promise rejection _expo.default.launchImageLibraryAsync error

already added camera storage permissions in app json

import React from 'react';
import { StyleSheet, Text, TouchableOpacity, View, Image } from 'react-native';
import Expo from 'expo';
import ImagePicker from 'expo';
import * as Permissions from 'expo-permissions';

export default class App extends React.Component {
  state = {
    image: null,
  };

  selectPicture = async () => {
    await Permissions.askAsync(Permissions.CAMERA_ROLL);
    const { cancelled, uri } = await ImagePicker.launchImageLibraryAsync({
      aspect: 1,
      allowsEditing: true,
    });
    if (!cancelled) this.setState({ image: uri });
  };

  takePicture = async () => {
    await Permissions.askAsync(Permissions.CAMERA);
    const { cancelled, uri } = await ImagePicker.launchCameraAsync({
      allowsEditing: false,
    });
    this.setState({ image: uri });
  };

  render() {
    return (
      <View style={styles.container}>
        <Image style={styles.image} source={{ uri: this.state.image }} />
        <View style={styles.row}>
          <Button onPress={this.selectPicture}>Gallery</Button>
          <Button onPress={this.takePicture}>Camera</Button>
        </View>
      </View>
    );
  }
}

const Button = ({ onPress, children }) => (
  <TouchableOpacity style={styles.button} onPress={onPress}>
    <Text style={styles.text}>{children}</Text>
  </TouchableOpacity>
);

want to upload image

Satish Lodhi
  • 89
  • 1
  • 1
  • 6

1 Answers1

0

You have to ask for proper permission from the user to access the camera. You have to import permissions API from Expo and then ask for camera permission on demand. Adding the permission in App.json won't work as it wont ask the user for permission to allow for camera. You have to add Permission API and then ask the user for camera permission and based on the permission render the camera.

Rishav Kumar
  • 4,979
  • 1
  • 17
  • 32