Firebase存储随机返回storage/canceled

8
我遇到了一个错误,提示上传被用户取消,并且在控制台上出现了三个相同的错误(来自Firebase存储的文件上传)。我无法看到代码中如何进行取消操作(假设因为它声明是由用户取消的,那么它应该在代码中)。
  startUpload(event: FileList, item:string) {
    // The File object
    const file = event.item(0);
    console.log(item);

    // Client-side validation example
    if (file.type.split('/')[0] !== 'image') { 
      console.error('unsupported file type')
      return;
    }

    // The storage path
    const path = `test/${new Date().getTime()}_${file.name}`;

    // Totally optional metadata
    const customMetadata = { user: item };

    // The main task
    this.uploadStatus = 'inprogress';
    this.task = this.storage.upload(path, file, { customMetadata })
    const fileRef = this.storage.ref(path);

    // Progress monitoring
    this.percentage = this.task.percentageChanges();
    this.snapshot = this.task.snapshotChanges().pipe(
      tap(snap => {
        if (snap.bytesTransferred === snap.totalBytes) {
          // Update firestore on completion
          this.db.collection('photos').add( { path, size: snap.totalBytes }); 
          this.uploadStatus = "finished";
        }
      }),
      finalize(()=>{
        this.downloadURL = fileRef.getDownloadURL();
        console.log("Final");
      })
    );

}

完整的错误信息来自Chrome控制台: "storage/canceled" code_: "storage/canceled" message: "Firebase Storage:用户取消了上传/下载。" message_: "Firebase存储:用户取消了上传/下载。" name(...): name_: "FirebaseError" serverResponse: null serverResponse_: null
Firebase存储:展示一些上传工作(即使我出现了错误): Firebase Randomly works
1个回答

5
我刚遇到了这个错误:
FirebaseStorageError {code_: "storage/canceled", message_: "Firebase Storage: User canceled the upload/download.", serverResponse_: null, name_: "FirebaseError"}

我的原始观点

 <mat-progress-bar mode="determinate" *ngIf="(uploadPercent | async) == 0" [value]="uploadPercent | async"></mat-progress-bar>

| async

罪魁祸首是取消可观察对象的元凶。

解决方案:

        <ng-container *ngIf="(uploadPercent$ | async); let uploadPercent">
            <mat-progress-bar mode="determinate" *ngIf="uploadPercent !== 100" [value]="uploadPercent"></mat-progress-bar>
        </ng-container>

1
好的解决方案!谢谢。我也在做同样的事情... 当进度条达到100%时隐藏它。 - Muhammad bin Yusrat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接