Please check error, the error show: Key "cancelled" in the image picker result is deprecated. By the way I used canceled
import React, { useEffect, useState } from 'react'
import { Alert, Button, Image, View, StyleSheet,Platform } from 'react-native'
import * as ImagePicker from 'expo-image-picker'
import Constants from 'expo-constants'
const Fine_Repair_Request = () => {
const [image,setimage] = useState(null);
useEffect( async() => {
if(Platform.OS !== 'web'){
const {status} =await ImagePicker.requestMediaLibraryPermissionsAsync();
if(status !== 'granted'){
alert('Permission denied')
}
}
},[])
const PickImage = async()=>{
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing:true,
aspect:[4,3],
quality:1
})
console.log(result)
if(!result.canceled){
setimage(result.uri)
}
}
return (
<View style={styles.container}>
<Button title="Upload Image" onPress={PickImage} />
{image && <Image source={{uri:image}}/>}
</View>
)
}
export default Fine_Repair_Request;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
})
- Error: WARN Key "cancelled" in the image picker result is deprecated and will be removed in SDK 48, use "canceled" instead
WARN Key "uri" in the image picker result is deprecated and will be removed in SDK 48, you can access selected assets through the "assets" array instead
2
Answers
for Error: WARN Key "cancelled" try
and for WARN Key "uri"
then the full code :
So, your problem is that you are accessing a deprecated propertie and you aren’t accessing ok to the uri of the image.
From the
expo-image-picker
this is what a result response looks like:In order to be able to get the uri of the selected asset you have to access the
assets
array and then the image:The propertie
cancelled
is deprecated also, so just use the key that they are suggesting to youcanceled