【发布时间】:2018-12-28 00:52:01
【问题描述】:
我在这里想要完成的是一个简单的想法。
将文件上传到 Firebase 存储
获取文件的链接并将其插入表单中。
问题是,我无法获取下载地址。
当我上传某些内容时,它确实会上传,但我收到以下错误消息:
Object { code_: "storage/object-not-found", message_: "Firebase Storage: Object 'rnmgm3vvpz' does not exist.", serverResponse_: "{\n \"error\": {\n \"code\": 404,\n \"message\": \"Not Found. Could not get object\"\n }\n}", name_: "FirebaseError" }
这是要上传到component.ts的代码:
upload(event) {
const id = Math.random().toString(36).substring(2);
this.ref = this.afStorage.ref(id);
this.task = this.ref.put(event.target.files[0]);
this.uploadState = this.task.snapshotChanges().pipe(map(s => s.state));
this.uploadProgress = this.task.percentageChanges();
this.downloadURL = this.ref.getDownloadURL();
}
在component.html上:
<input type="file" (change)="upload($event)" accept=".png,.jpg" />
文件上传后如何获取downloadURL?
【问题讨论】:
-
试试这个答案在这个时间点是如何工作的https://stackoverflow.com/a/57267424/11127383
-
找不到对象,因为应该在文件完成加载后进行 downloadURL 调用。如@dAxx_所述,将其从uploadEvent 函数中删除并添加到finalize 函数中
标签: angular firebase google-cloud-firestore