简体   繁体   English

HTTPS 图像未在 React Native 图像中呈现

[英]HTTPS image not rendering in react native image

I am trying to render an image " https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg " which works fine in a web browser, but in a react-native image the image does not appear.我正在尝试渲染图像“ https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg ”,它在网络浏览器中工作正常,但在反应原生图像中,图像不会出现。

I am attempting to do :我正在尝试做:

 <Image
style={{ height: 200, width: 200 }}
source={{
    uri:
        "https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg"
}}
/>;

This also does not work:这也不起作用:

 <Image
style={{ flex: 1, resizeMode: "cover" }}
source={{
    uri:
        "https://www.edamam.com/web-img/22c/22c27bdc6b8dc67215c7478cb4e5dc42.jpg"
}}
/>;

What am I doing incorrectly here?我在这里做错了什么?

I tried your code, initially I did not get the image, then I handle the error using onError handler and found the following error我尝试了你的代码,最初我没有得到图像,然后我使用onError处理程序处理错误并发现以下错误

An SSL error has occurred and a secure connection to the server cannot be made发生 SSL 错误,无法与服务器建立安全连接

You may look into the stackoverflow answers for this error here您可以在此处查看此错误的 stackoverflow 答案

I tried the first solution by changing我通过改变尝试了第一个解决方案

info.plist信息.plist

with following configuration and it worked使用以下配置,它工作正常

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Have a look into this document, above approach is not recommended , instead they have suggested other way (it is also mentioned in the linked stackoverflow answer).查看文档,不推荐使用上述方法,而是建议使用其他方法(链接的stackoverflow 答案中也提到了这一点)。

Hope this will help.希望这会有所帮助。

For anyone who thinks this is not a HTTPS issue, also check that your image is not a webp image.对于认为这不是 HTTPS 问题的任何人,还要检查您的图像是否不是 webp 图像。

Even if the title of the image says it's a .png or .jpg, try to save the image.即使图像的标题说它是 .png 或 .jpg,也要尝试保存图像。 If it says Google's WebP then you'll need to convert the image into a React Native friendly image file type.如果它说的是 Google 的 WebP,那么您需要将图像转换为 React Native 友好的图像文件类型。

Hope this helps!希望这可以帮助!

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

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