【问题标题】:I can't view the picture in the firebase storage我无法在 Firebase 存储中查看图片
【发布时间】:2021-04-21 00:55:24
【问题描述】:

我的获取代码

` getImage = async (imageUrl) => {
    const user = firebase.auth().currentUser;
    const url = await storage()
        .ref(`Users/${user.uid}/picture`)
        .getDownloadURL()
    console.log(url)
    imageUrl = url;
    let imgSource = { uri: imageUrl }; // change this line
    if (isNaN(imageUrl)) {
      imgSource = { uri: this.state.imageUrl };
      if (Platform.OS == 'android') {
        imgSource.uri = "file:///" + imgSource.uri;
      }
    }
    
}


  render() {

    let {imageUrl} = this.state;

    return (
        <View>
             <Image source={this.getImage(imageUrl)} style={{width:200,height:200}}/> 
        </View>

` console screenshot 我可以从我的控制台获取网址,但图片没有显示在我的应用程序中,这是什么问题

【问题讨论】:

    标签: react-native firebase-storage


    【解决方案1】:

    这可能会有所帮助

    state = { newImageURL : undefined }
    
    getImage = async (imageUrl) => {
        const user = firebase.auth().currentUser;
        const url = await storage()
            .ref(`Users/${user.uid}/picture`)
            .getDownloadURL()
        console.log(url)
        imageUrl = url;
        let imgSource = { uri: imageUrl }; // change this line
        if (isNaN(imageUrl)) {
          imgSource = { uri: this.state.imageUrl };
          if (Platform.OS == 'android') {
            imgSource.uri = "file:///" + imgSource.uri;
          }
        }
        this.setState({ newImageURL: imgSource }); // update code here
        
    }
    
    componentDidMount(){
      let {imageUrl} = this.state;
      this.getImage(imageUrl)
    }
    
    
      render() {
        return (
            <View>
                 {newImageURL ? <Image source={newImageURL} style={{width:200,height:200}}/> : null }
            </View>
    

    【讨论】:

    • 我会试试这个。谢谢你的帮助
    • 我已经解决了这个问题,感谢您的宝贵时间
    猜你喜欢
    • 2017-09-21
    • 2021-08-18
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 2016-11-28
    相关资源
    最近更新 更多