How can I get the name of the file in expo-image-picker?

132 views Asked by At

Im using react native to make a app, and I have a problem using expo-image-picker,how Can I show the name of the file that I choose? in documentation doesnt appear any related

this is my code:

   const pickImage = async () => {
        // No permissions request is necessary for launching the image library
        let result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions.All,
            allowsEditing: true,
            aspect: [4, 3],
            quality: 1,
        });

        console.log(result);

        if (!result.canceled) {
            setImage(result.assets[0].uri);


        }
    };


this is the log

{"assets": [{"assetId": null, "base64": null, "duration": null, "exif": null, "height": 808, "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252FcapstoneMobile-d6c5868c-1685-4858-8028-d15f7abf2491/ImagePicker/ea8dfdbf-f924-4ec7-8dce-d3378d434b45.jpeg", "width": 1078}], "canceled": false, "cancelled": false}

I need to extract the name of the file (ea8dfdbf-f924-4ec7-8dce-d3378d434b45.jpeg is not)

1

There are 1 answers

1
Kadi On

You can extract it from the file path:

const fileName = result.assets[0].uri.split('/').pop();