简体   繁体   English

如何从 Flutter 中的 url 获取 Image 的扩展名?

[英]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). url 看起来像 https://myImageUrl(没有对扩展的引用)。
I want to show this image but i don't know if it's an svg or a jpg.我想展示这张图片,但我不知道它是 svg 还是 jpg。
Is there a way to get the image's extension from its url?有没有办法从其 url 获取图像的扩展名? I've tried mime package https://pub.dev/packages/mime but it doesn't work.我试过 mime 包https://pub.dev/packages/mime但它不起作用。
I need to know the image's extension because:我需要知道图像的扩展名,因为:

  • if it's a svg I'll use SVG library如果是 svg,我将使用 SVG 库
  • if it's a jpg I'll use Image.network('myImageUrl')如果是 jpg,我会使用Image.network('myImageUrl')

Is there a way to get the image's extension from its url有没有办法从它的 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.因为如果它是一个 svg(这看起来很奇怪,但没关系),你想从资产加载它,你可以只检查给定的 URL 对所有资产......如果它在他们的,从资产中显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM