angular - 即使在 AngularFire2 的 Firebase 存储中取消上传任务后,快照状态仍为 'running'

标签 angular firebase firebase-storage angularfire2

我正在使用 AngularFire2Firebase 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/

相关文章:

java - 我在 Recyclerview 中显示来自 firebase 的图像时遇到问题

javascript - 如何有条件地将行添加到 Angular 5的表中

javascript - 在标记页面中,如何向 html 标记的 textContent 属性添加内容?

firebase - 如何从没有快照的 Angular firestore 文档获取 UID

android - 在 Android 中使用 Firebase 流式传输视频

android - 在 android 中捕获图像时新的 firebase 屏幕变黑

angular - 如何创建跨域请求?

css - 从位于 JSON 中的 url 获取图像

javascript - Firebase .on ('value' ) 不工作

android - 将 ProGuard 映射文件上传到 Firebase 以获得多种风格和构建类型