noobCoder
noobCoder

Reputation: 13

React Native Expo image picker having issue while calling the api and submitting the form only in Android

I'm working in one react native expo project and im using only expo go compatible packages. In this app i need a form for one of my screen, in that form i need a two image uploads. For this uploads I'm using expo image picker, its working perfectly when taking picture and editing and storing it in the State but i had a issue when submitting the form and the api isnt working, without this image picker its working fine but with that, its not working but when we refesh the app it working but again edit the image and submit it again the same issue happen, so i concluded with that the issue with expo image picker and i confirm there is no isssue with the api

export const DocumentUpload = ({ file, setFile, containerStyle }) => {
  const [status, requestPermission] = ImagePicker.useCameraPermissions();

  const pickImage = async () => {
    try {
      // Asking for camera permission when the component mounts
      if (!status?.granted) {
        Alert.alert(
          "Permission Required",
          "Sorry, we need your camera permission to make this work.",
          [{ text: "Grant Permission", onPress: requestPermission }]
        );
      } else {
        ImagePicker.launchCameraAsync({
          cameraType: ImagePicker.CameraType.back,
          allowsEditing: true,
          aspect: [9, 16],
          quality: 0.3,
        }).then((result) => {
          if (!result.canceled) {
            // The user is setting an image.
            setFile(result.assets[0].uri);
          }
        });
      }
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <TouchableOpacity
      style={[styles.uploadContainer, containerStyle]}
      onPress={() => {
        pickImage();
      }}
    >
      {file ? (
        <Image style={styles.uploadedImgStyle} source={{ uri: file }} />
      ) : (
        <View style={styles.uploadIconContainer}>
          <FontAwesome
            name="camera"
            color={COLORS.primaryColor2 + "50"}
            size={25}
          />
          <Text style={styles.uploadText}>Take a Picture</Text>
        </View>
      )}
    </TouchableOpacity>
  );
};

I tried with the expo camera its working fine when initial submit and after editing as well, but i need expo image picker which had builtin option for editing and is really opt for this purpose. Could anyone please tell? is the issue with expo image picker and give the solution for this. Thank you

Upvotes: 0

Views: 103

Answers (0)

Related Questions