我正在使用 AngularFire2
在 Firebase Storage
中上传文件:
this.task = this.storage.upload(uploadPath, file);
this.task.snapshotChanges()
.subscribe(snapshot => {
this.snapshot = snapshot;
});
它按预期工作,但是,当我通过 cancel()
方法取消 task
时,snapshot
不会改变,因此状态
是正在运行
,而不是已取消
。这是为什么?
this.task.cancel();
// this.snapshot.state === 'running', not 'cancelled'
最佳答案
似乎是一个真正的错误
最后一个事件不会在 snapshotChanges() 上发出,但会在 .then() Promise 中发出
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
});
关于angular - 即使在 AngularFire2 的 Firebase 存储中取消上传任务后,快照状态仍为 'running',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51704014/