【问题标题】:react native firebase realtime data base not display show photo反应本机firebase实时数据库不显示显示照片
【发布时间】:2020-07-02 19:51:29
【问题描述】:

我使用firebase实时数据库,我可以提取照片数据 但是会在实时数据库中使用照片,它不会显示组件平面列表。

我的代码获取数据库:

componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
  if (user != null) {
    const rootRef = firebase.database().ref();
    const userRef = rootRef.child(`user/${user.uid}/car`);
    this.setState({ uid: user.uid })
    userRef.on('value', (childSnapshot) => {
      const cars = [];
      childSnapshot.forEach((doc) => {
        cars.push({
          distance: doc.val().distance,
          time: doc.val().time,
          price: doc.val().price,
          photo:doc.val().photo,
          key: doc.key,
        });
        this.setState({
          cars: Object.values(cars)
        })
      });
    })
  }
});

}

扁平化

<FlatList data={this.state.cars}
          renderItem={({ item }) => (
            <List>
              <ListItem avatar>
                  <Image style={{width:50,height:50}} source={item.photo}></Image>
              </ListItem>
            </List>)}
        />

不是秀照片"Picture"

【问题讨论】:

    标签: node.js firebase react-native firebase-realtime-database


    【解决方案1】:

    您存储到照片的链接是您添加照片的设备上的本地文件 URL。这仅适用于已存在照片的设备,即便如此,它也可能随时停止工作。

    您需要将照片上传到所有用户都可以看到的服务器。例如,您可以upload the photo with the Firebase Storage SDK,然后请求一个下载 URL(参见this example 的末尾),然后将 那个 URL 写入数据库。有了这样的下载网址,所有用户都可以阅读图片。

    【讨论】:

    • 好的,我会试试的。谢谢。
    猜你喜欢
    • 2022-01-02
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多