Issue
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
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.
Additional Information
- React Native version: ~0.46.1
- React: 16.0.0-alpha.12
- Platform: [Android 5.1 and above]
- Development Operating System: [Windows 7 Professional]
- Dev tools: [ Android Studio version 2.3.2, Android SDK 23]
Solution
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
Answered By - Zafar Kurbonov
Answer Checked By - Clifford M. (JavaFixing Volunteer)