I am trying to upload an image from internal memory in our client app, using
react-native-image-picker@^0.26.4
And after executing the following sample snippet i got the response in an unexpected way.
ImagePicker.showImagePicker(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)
} else {
const source = { uri: response.uri }
// RNGRP.getRealPathFromURI(response.uri).then(filePath => {
// uploadImageToS3(filePath, "dinesh")
// console.log(filePath)
// })
// You can also display the image using data:
// let source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source
})
}
Response = {error: "Permissions weren't granted"} error: "Permissions weren't granted"proto: Object D:\my_app\index.js:124 ImagePicker Error: Permissions weren't granted
Sometimes On Allow button press app unexpectedly crashes.
Add this code in your AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Edited this after suggestions by Jaffar Raza and szskdgi
Add this code in the android/app/src/main/AndroidManifiest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
after adding the following permission to AndroidManifiest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
we should have checked the permission before processing the functionality.
ex :- step 1(check permission whether it's GRANTED or not)
const isCameraAuthorized = await permissions.checkPermission(
PermissionType.CAMERA
);
enter code here
step 2(request permission)
cameraPermissionStatus = await permissions.requestPermission(
PermissionType.CAMERA
);
then we have do the same for WRITE_EXTERNAL_STORAGE as
cameraPermissionStatus = await permissions.requestPermission(
PermissionType.WRITE_EXTERNAL_STORAGE
);
const isCameraAuthorized = await permissions.checkPermission(
PermissionType.WRITE_EXTERNAL_STORAGE
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With