首页 > 解决方案 > 如何在Angular中按顺序上传文件?

问题描述

我目前有一个将多个文件上传到 Azure Blob 存储的解决方案,但进度条不会在每个文件后重置(保持在 100)。

我知道您可以使用 Promise,但我是 Angular 新手,不知道如何最好地使用它?

这是我当前的代码(有效)它将文件存储在数组中

上传文件() {

while (this.targetFiles.length > 0)
{
    this.targetFile = this.targetFiles.pop();
    this.uploadProgress = this.blob
    .uploadToBlobStorage(accessToken, this.targetFile);


    this.currentPageSub = 
    this.uploadProgress.subscribe((total: number) => {
      this.progress=total;
          });

} 

}

但我想一次上传一个文件,在上传文件后重置订阅功能中的进度条(this.progress)

有什么建议么?

标签: htmlangularazureangular5

解决方案


您应该重置每个周期的进度。

 while (this.targetFiles.length > 0)
{
    this.progress=0;
    this.targetFile = this.targetFiles.pop();
    this.uploadProgress = this.blob
    .uploadToBlobStorage(accessToken, this.targetFile);


    this.currentPageSub = 
    this.uploadProgress.subscribe((total: number) => {
      this.progress=total;
          });

 } 
}

推荐阅读