当我更改文件时,它在firebase存储中成功更新,但是当我尝试获取downloadURL时,它显示为null。
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);
}
答案 0 :(得分:2)
put()是异步的。如果你想在文件上传后获取网址,你必须这样做:
firebase.storage().ref().child(`${imageFolder}/profile.jpg`).put(file).then((snapshot) => {
storageRef = snapshot.downloadURL:
console.log(snapshot.downloadURL);
});