【问题标题】:get an image from Firebase Storage in React Native从 React Native 中的 Firebase 存储获取图像
【发布时间】:2020-04-09 07:49:07
【问题描述】:

我正在尝试以 react native 显示 firebase 存储图像。我设法将图像写入 Firebase 存储,但现在我还想在应用程序中显示它。不幸的是,我试图理解文档但没有成功。有没有人可以帮助我?

我正在尝试让用户上传图像,然后它应该显示为图像。上传成功,在此处查看我的 firebase 存储:

现在我正在尝试从 firebase 存储中获取图像并使用以下代码显示它:

  componentDidMount(){    
  this.imageUploaded = firebase.storage().ref('images/profilepictures/536887a2-c8fe-4c60-b2f1-3864f691fa9e.jpg').getDownloadURL().toString();

    console.log(this.imageUploaded);
  }

但是,console.log (this.imageUploaded) = [object object] 和图像中的结果保持空白:

<Avatar size="large" rounded source={{uri: this.imageUploaded }} onPress={() => console.log("Works!")} activeOpacity={0.7} />

什么都不显示。有没有人可以帮助我理解这一点?非常感谢您!

【问题讨论】:

    标签: react-native firebase-storage


    【解决方案1】:

    改变

      this.imageUploaded = firebase.storage().ref('images/profilepictures/536887a2-c8fe-4c60-b2f1-3864f691fa9e.jpg').getDownloadURL().toString();
        console.log(this.imageUploaded);
    

    var ref = firebase.storage().ref('images/profilepictures/536887a2-c8fe-4c60-b2f1-3864f691fa9e.jpg');
    this.imageUploaded = await ref.getDownloadURL();
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 2018-07-08
      • 2017-12-29
      • 2020-08-26
      • 2020-04-23
      相关资源
      最近更新 更多