angular - 即使在取消 AngularFire2 的 Firebase 存储中的上传任务后,快照状态仍为“正在运行”
问题描述
我AngularFire2
用来上传文件Firebase Storage
:
this.task = this.storage.upload(uploadPath, file);
this.task.snapshotChanges()
.subscribe(snapshot => {
this.snapshot = snapshot;
});
它按预期工作,但是,当我task
通过该cancel()
方法取消时,snapshot
不会改变,因此state
是running
,而不是cancelled
. 这是为什么?
this.task.cancel();
// this.snapshot.state === 'running', not 'cancelled'
解决方案
似乎是一个真正的错误
最后一个事件不会在 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
});