skip to Main Content

I am working on an Image picker on react native. Im getting a warning … 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. I am getting on both android emulator and IOS How can I overcome this?

const selectImage = async () =>{
        try {
            const result = await ImagePicker.launchImageLibraryAsync({
                mediaTypes: ImagePicker.MediaTypeOptions.Images,
                allowsEditing: true,
                aspect: [4, 3],
                quality: 0.5
            });
            
            if(!result.canceled){
               setImage(result.uri)
               saveToFile();
            }else Alert.alert('Delete', 'Are you sure you want to delte the image', [
                {text:"Yes", onPress:()=> setImage(null)},{text:"No"} ])
            
        } catch (error) {
            console.log("error reading an image")
            
        }
    }

2

Answers


  1. setImage(result.assets[0].uri) instead of

    setImage(result.uri)

    This will solve but will land you in a new problem of promises which I am also figuring out.

    Login or Signup to reply.
  2. I have been trying hard for 3 days but this (result.assets[0].uri) didnt work for me! But suddenly I found this solution below I hope it also works for you:

    Just install this in the frontend:

    npx expo install expo-image-picker

    and I add this in your app.json under expo

    "plugins": ["expo-image-picker"],

    I hope it works for you too

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search