Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get Image's extension from url in Flutter?

I have an url that corresponds to an image.
The url looks like https://myImageUrl (there’s no reference to the extension).
I want to show this image but i don’t know if it’s an svg or a jpg.
Is there a way to get the image’s extension from its url? I’ve tried mime package https://pub.dev/packages/mime but it doesn’t work.
I need to know the image’s extension because:

  • if it’s a svg I’ll use SVG library
  • if it’s a jpg I’ll use Image.network('myImageUrl')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to get the image’s extension from its url

No. If it’s not there, it’s not there. There is no magic available that would show missing information.

Since you want to load it from assets if it’s an svg (which seems weird, but okay), you could just check the given URL against all assets… if it’s in their, show it from assets.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading