未处理的承诺拒绝:FirebaseStorageError{code_:“存储/找不到对象”,message_:"Firebase存储:对象'k91a73uzb99‘不存在。“,serverResponse_:"{↵”错误“:{↵”代码“:404,↵”消息“:"No…not get object",状态“:”GET_OBJECT“↵}↵}”,name_:"FirebaseError"}
export class ReportComponent implements OnInit {
ref: AngularFireStorageReference;
task: AngularFireUploadTask;
newUrl: Observable<string>;
constructor(private firesStore: AngularFireStorage,
) { }
ngOnInit() { }
async onSelectFile(event) {
const id = Math.random().toString(36).substring(2);
this.ref = this.fireStore.ref(id);
this.task = this.ref.put(event.target.files[0]); /*
.snapshotChanges()
.subscribe( (value) => {
}); */
this.uploadPercent = this.task.percentageChanges();
// get notified when the download URL is available
this.task.snapshotChanges().pipe(
finalize(() => {
this.newUrl = this.ref.getDownloadURL();
console.log(this.newUrl);
})
).subscribe();
}
预期:https://firebasestorage.googleapis.com/v0/b/< storageBucket >/o/< ref(id) >?alt=media&token=<........>
实际:https://firebasestorage.googleapis.com/v0/b/< storageBucket >/o/< ref(id) >
发布于 2019-06-20 00:44:08
错误消息显示“存储/未找到对象”和“对象'k91a73uzb99‘不存在”。这意味着您正在上传的文件包含以下代码行:
this.ref = this.firesStore.ref(id);
this.task = this.ref.put(event.target.files[0]);
尚未完成上传。您正在尝试在上载完成之前获取其下载URL:
this.newUrl = await this.firesStore.ref(id).getDownloadURL();
您需要遵循使用返回的AngularFireUploadTask的example code from the documentation,在访问其下载URL之前等待上传完成。所以,它会是这样的:
this.uploadPercent = task.percentageChanges();
// get notified when the download URL is available
task.snapshotChanges().pipe(
finalize(() => this.newUrl = this.ref.getDownloadURL() )
)
.subscribe()
https://stackoverflow.com/questions/56672315
复制相似问题