Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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")
            
        }
    }
like image 431
Ephrat Negussie Avatar asked Sep 06 '25 03:09

Ephrat Negussie


2 Answers

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.

like image 182
Sourabh Avatar answered Sep 07 '25 21:09

Sourabh


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

like image 37
Awara Amini Avatar answered Sep 07 '25 20:09

Awara Amini