【发布时间】:2019-03-25 20:39:31
【问题描述】:
我正在使用 Angular 和 Firebase 存储来上传图像,当我尝试在 tap 内的 console.log 中打印时,我遇到了问题,我的 urlImg 是 undefined。
this.snapshot = this.snapshot = this.task.snapshotChanges().pipe(
finalize(() => {
this.storage
.ref(path)
.getDownloadURL()
.subscribe(url => {
this.urlImg = url; // with this you can use it in the html
});
}),
tap(snap => {
if (snap.bytesTransferred === snap.totalBytes) {
// Update firestore on completion
//Code to upload on completion
console.log("url");
console.log(this.urlImg);
}
})
);
【问题讨论】:
-
tap将在finalize之前发生,因为finalize是最后发生的事情 -
@user184994 哦,我不是那个!有什么建议?关于如何解决这个问题?
-
这取决于你真正想要做什么。如果需要,您显然可以从
subscribe中访问this.urlImg? -
我想等待文件上传,然后在 Firebase 存储中获取图像的 url,然后将位于 Firebase 存储中的图像的 url 上传到 firestore @user184994
标签: angular firebase rxjs google-cloud-firestore observable