numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
917 stars 86 forks source link

Gracefully handle non-image files for getImageMetaData (currently crashes the app on iOS) #283

Open ChristopherGabba opened 6 months ago

ChristopherGabba commented 6 months ago

Current behavior

Currently if you feed a file that is not an image into getImageMetaData, the app hard crashes. I was using this function to test if a url was an image or not.

export async function isValidImage(url: string) {
  try {
    // Check if the fetched data is an image
      const imageData = await getImageMetaData(url)
      return imageData.extension !== "unknown"Ï
  } catch (error) {
    console.log("IMAGE ERROR", error)
    return false
  }
}

Expected behavior

The function returns an extension of "unknown".

Platform

Works on android but not on iOS.

React Native Version

"react-native": "0.73.6",

React Native Compressor Version

"react-native-compressor": "^1.8.23",

Reproducible Steps And Demo

Simply feed this url into the getImageMetaData function: https://www.instagram.com/reel/C49E_fuvM90/

github-actions[bot] commented 6 months ago

👋 @ChristopherGabba Thanks for opening your issue here! If you find this package useful hit the star🌟!