admin管理员组文章数量:1431434
I'm trying to display my uploaded image saved from to my backend folder. Its on different file so to retrieve I have to call it http://localhost:3333/userprofile/5/5.jpeg. But it does not work on my react native code, I tested it on both android and IOS
<Thumbnail
small
source={{
uri: `http://localhost:3333/userprofile/${this.props.user.id}/${this.props.user.avatar}`
}}
/>
it works when I open it on browser. It also work if I use different url like /200/300 how to deal with this?
I'm trying to display my uploaded image saved from to my backend folder. Its on different file so to retrieve I have to call it http://localhost:3333/userprofile/5/5.jpeg. But it does not work on my react native code, I tested it on both android and IOS
<Thumbnail
small
source={{
uri: `http://localhost:3333/userprofile/${this.props.user.id}/${this.props.user.avatar}`
}}
/>
it works when I open it on browser. It also work if I use different url like https://picsum.photos/200/300 how to deal with this?
Share Improve this question edited Sep 20, 2019 at 8:46 ravibagul91 20.8k6 gold badges38 silver badges61 bronze badges asked Sep 20, 2019 at 8:42 BGTabulation BGTabulateBGTabulation BGTabulate 1,7473 gold badges20 silver badges40 bronze badges 8- You probably have CORS error – Lazar Nikolic Commented Sep 20, 2019 at 8:44
-
Are you sure
this.props.user.avatar
contains extension like.jpeg
? If not you need to add it manually. – ravibagul91 Commented Sep 20, 2019 at 8:48 -
source={{...}}
I have doubt on this json syntax – Jaydip Jadhav Commented Sep 20, 2019 at 8:49 - @LazarNikolic My cors config are open for all – BGTabulation BGTabulate Commented Sep 20, 2019 at 8:49
-
@ravibagul91 if I outputed in text its exactly
http:/localhost:3333/userprofile/5/5.jpeg
and when I copy and paste on browser it works – BGTabulation BGTabulate Commented Sep 20, 2019 at 8:51
3 Answers
Reset to default 4If you're using android emulator you have to use 10.0.2.2
to access localhost on your PC. and if you're using a real device then you need to be on the same wifi network and have to use your PC's ip instead of localhost
From the docs,
Many of the images you will display in your app will not be available at pile time, or you will want to load some dynamically to keep the binary size down. Unlike with static resources, you will need to manually specify the dimensions of your image. It's highly remended that you use https as well in order to satisfy App Transport Security requirements on iOS.
You need to provide dimensions for your image.
<Thumbnail
small
source={{
uri: `http://localhost:3333/userprofile/${this.props.user.id}/${this.props.user.avatar}`
}}
style={{width: 400, height: 400}} //provide dimensions
/>
Use your IP Adress insted localhost
<Thumbnail
small
source={{
uri: http://<Your IP Adress>:3333/userprofile/${this.props.user.id}/${this.props.user.avatar}
}}
/>
本文标签: javascriptReact Native Serving URI from localhost not rendering the imageStack Overflow
版权声明:本文标题:javascript - React Native: Serving URI from localhost not rendering the image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745564593a2663681.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论