【问题标题】:DownloadURL return null in below codeDownloadURL 在下面的代码中返回 null
【发布时间】:2017-08-18 13:36:35
【问题描述】:

当我更改文件时,它在 firebase 存储中成功更新,但是当我尝试获取 downloadURL 时,它显示为空。

fileChange(event: any) {
    const imageFolder: string = this.employee.id;
    const fileList: FileList = event.target.files;
    const file: File = fileList[0];
    const storageRef = firebase.storage().ref().child(`${imageFolder}/profile.jpg`).put(file);
    console.log(storageRef.snapshot.downloadURL);
}

【问题讨论】:

    标签: angular firebase firebase-storage


    【解决方案1】:

    put() 是异步的。如果您想在文件上传后获取 url,您必须这样做:

    firebase.storage().ref().child(`${imageFolder}/profile.jpg`).put(file).then((snapshot) => {
         storageRef  = snapshot.downloadURL:
         console.log(snapshot.downloadURL);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多