My app keeps crashing when user tries to send photo from camera to API. This issue started to happen after I set the permissions for the app in app.json. There were no problem in the android emulator but it crashes on my Galaxy A30. Is there a permission that I'm missing or the permission that I set is wrong
app.json
"plugins": [
[
"expo-image-picker",
{
"photosPermission": "custom photos permission",
"cameraPermission": "Allow $(PRODUCT_NAME) to open the camera",
"//": "Disables the microphone permission",
"microphonePermission": false
}
]
],
"android": {
"package":"myapp.myapp",
"versionCode": 2,
"permissions": ["CAMERA", "READ_EXTERNAL_STORAGE"],
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
SubmissionScreen,js
import * as Permissions from "expo-permissions";
import { CAMERA } from "expo-permissions";
import * as ImagePicker from 'expo-image-picker';
const [allImage, setAllImage] = React.useState([]);
const useCamera = async () => {
const hasPermissions = await cameraPermission();
if (!hasPermissions) {
return;
}
if(allImage.length < 4){
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
quality: 0.5,
});
if (!result.cancelled) {
const name = result.uri.split('/').pop();
let match = /.(w+)$/.exec(name);
let type = match ? `image/${match[1]}` : `image`;
let newFile = {
uri: result.uri,
type: type,
name: name
}
setAllImage(newFile)
setPickedImage(result.uri)
if (!pickedImage && allImage.length === 0) {
setAllImage([newFile]);
setFileName("Receipt 1")
}else {
setAllImage([...allImage, newFile]);
setFileName(fileName + ", Receipt " + (allImage.length + 1))
}
}
}
};
const fetchData = () => {
allImage.forEach((file) => {
formdata.append('files[]', file);
});
axios({
method: 'post',
url: URLs._uploadReceipt,
data: formdata,
}).then(function (result) {
if(result.data.message === "Receipt Successfully added") {
navigation.goBack()
}
});
}
return (
<TouchableOpacity style={[GlobalStyle.UploadButtonContainer]} activeOpacity={0.8} onPress={useCamera}>
<FontAwesome5 style={[GlobalStyle.BrowseIcon]} name="camera"/>
<Text style={[GlobalStyle.BrowseText]}>Camera</Text>
</TouchableOpacity>
<TouchableOpacity style={[GlobalStyle.ConfirmButton, {marginRight: 15}]} activeOpacity={0.9} onPress={fetchData}>
<Text style={[GlobalStyle.BrowseText]}>Submit</Text>
</TouchableOpacity>
)