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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.