我想实现的是一个简单的想法。
将文件上传到Firebase Storage
获取文件链接并在表单中插入它。
问题是,我无法获取下载链接。
当我上传文件时,它确实上传了,但我收到了这个错误消息:
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?