如何使用 AngularFire Storage 知道上传何时完成

How to know when the upload is complete using AngularFire Storage

我正在尝试使用 AngularFire 将函数从使用本机 Firebase 库转换和上传到 AngularFire2 v5 库。我如何知道上传何时完成,以便我可以在之后 运行 添加其他命令。

const image = firebase.storage().ref().child(`${user.uid}/${path}`)
    .putString(this.imageData, "base64", metadata)
    .then(() => {
        this.progressState.next(EProgressState.fadeout);
    }).catch(() => {
        this.progressState.next(EProgressState.error);
        reject();
    });

这成功了。到目前为止,我正在尝试实施

this.task = this.afStorage.ref(`${user.uid}/${path}`)
    .putString(this.imageData, "base64", metadata);

但我似乎无法添加 .then(() => {}) 声明。

阅读 Github 个帖子后,我发现了这个 link。根据API Surface应该是

this.task = this.afStorage.ref(`${user.uid}/${path}`)
.putString(this.imageData, "base64", metadata);

this.task.then(res=>console.log('Success'));

但有些人已经做到了

this.task.then().then(res => {
  console.log('Success');
});

我不知道为什么要用then()两次