首页 > 解决方案 > 即使在取消 AngularFire2 的 Firebase 存储中的上传任务后,快照状态仍为“正在运行”

问题描述

AngularFire2用来上传文件Firebase Storage

this.task = this.storage.upload(uploadPath, file);

this.task.snapshotChanges()
            .subscribe(snapshot => {
                this.snapshot = snapshot;
            });

它按预期工作,但是,当我task通过该cancel()方法取消时,snapshot不会改变,因此staterunning,而不是cancelled. 这是为什么?

this.task.cancel();
// this.snapshot.state === 'running', not 'cancelled'

标签: angularfirebasefirebase-storageangularfire2

解决方案


似乎是一个真正的错误

最后一个事件不会在 snapshotChanges() 上发出,但是它将在 .then() 承诺中发出

this._task.snapshotChanges()
  .subscribe(snapshot => {
    this.snapshot = snapshot; // To get updates on progress
  });
this._task.then(snapshot => {
  this.snapshot = snapshot; // To know when it is done
}).catch(snapshot => {
  this.snapshot = this._task.task.snapshot; // To know whenever there is an error/cancel from user
});

推荐阅读