RedGiant
RedGiant

Reputation: 4748

An image picker returns uri `content://media/` without the extenstion in react native

I'm using an Image Picker from a framework called ant-design-mobile.

When an image is selected from the gallery, the picker returns an array like this

[
 {
   uri:'content://media/external/images/media/76',
   width:150,
   height:150
 }
]

How can I check the image extension (jpg/png) or image sizes at https://mobile.ant.design/components/image-picker/? Is there a library to do such things?

Upvotes: 0

Views: 1152

Answers (1)

hadribbt
hadribbt

Reputation: 13

The best solution I found on android to get a file extension is using react-native-fetch-blob.

You have to use the method stat from the filesystem. Here's an example who should work with you code:

    import RNFetchBlob from 'react-native-fetch-blob'

    RNFetchBlob.fs.stat(PATH)
        .then(stats => {
            let re = /(?:\.([^.]+))?$/,
                ext = re.exec(stats.filename)[1]
            console.log('EXTENSION : ', ext)
        })

Where PATH is your 'content://media/external/images/media/76'

Hope this helps

Upvotes: 1

Related Questions