在React Native中构建后图像未显示

时间:2020-10-14 08:31:05

标签: react-native

我正在显示类别及其图像。我从后端获取类别,它也返回url。在开发人员模式下,emülatör(android)显示类别图像,但是当我尝试使用npm build构建时(react-native run-android --variant release),图像未显示。我确定类别数据即将到来。图像来自s3存储桶,我将它们全部公开仍然没有任何变化。找不到关于此的解决方案。使用npm出现时运行android,但在构建后不显示。

<View style={{ borderColor:turkuazColor,borderStyle:"solid",borderWidth: 1,backgroundColor: whiteColor, width: width / 5, height: width / 5, alignItems: "center", justifyContent: "center", borderRadius: 99 }}>
    <Image source={{uri : img.uri}} resizeMode="contain" style={{ width: width / 6.5, height: width / 8.5, alignSelf: "center", marginBottom: 5 }} />
</View>

1 个答案:

答案 0 :(得分:0)

因此,找到了解决方案。在s3中,启用了静态网站托管,并且我正尝试从该url获取图像,但是在开发人员模式下,它可以工作,但在构建后不起作用。我开始使用s3 bucket的网址,该网址与静态托管网址不同

静态托管的URL中包含区域信息,例如“ us-east-3”。还添加了CORS配置。

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>GET</AllowedMethod>
   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>
   <AllowedMethod>HEAD</AllowedMethod>
   <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

现在一切都很好。