【发布时间】:2020-06-16 08:18:13
【问题描述】:
获取https://firebasestorage.googleapis.com/xxxxx/o/hw04.docx404 firebase 下载链接错误 t {code_: "storage/object-not-found", message_: "Firebase Storage: Object 'hw04.docx' does not exist.", serverResponse_: "{↵ "error": {↵ "code" : 404,↵ "message": "No...not get object",↵ "status": "GET_OBJECT"↵ }↵}", name_: "FirebaseError"}
这是我的代码 sn-p。
upload(event) {
const file = event.target.files[0];
this.randomId = file.name;
this.ref = this.afStorage.ref(this.randomId);
this.task = this.ref.put(file);
this.uploadProgress = this.task.percentageChanges();
console.log("before pipe",this.task);
this.ref.getDownloadURL().subscribe((url) => {
console.log("link", url)
this.downloadURL = url;
},
err => {
console.log("firebase download link err", err);
})
}
}
它在 60% 的情况下都能正常工作,否则会出现 404 下载链接错误。
有没有更好的方法来处理这个异步响应?
请帮帮我!
谢谢,
【问题讨论】:
-
你有一个竞争条件。您应该等到上传完全完成后再获取下载 URL。
-
你是对的。谢谢@DougStevenson
标签: angular firebase firebase-storage angularfire2