javascript - Firebase 存储随机返回存储/取消

标签 javascript firebase firebase-storage

我收到一条错误消息,指出上传已被用户取消,并且我在控制台中的一次上传中收到三个错误(上传文件时来自 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 控制台的完整错误: “存储/取消” 代码_ : “存储/取消” 信息 : “Firebase 存储:用户取消了上传/下载。” 信息_ : “Firebase 存储:用户取消了上传/下载。” 名称 : (...) 名称_ : “火力地堡错误” 服务器响应 : 无效的 服务器响应_ : 空

Firebase 存储:显示一些上传有效(即使我收到错误): Firebase Randomly works

最佳答案

我自己也遇到了这个错误:

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

是取消 observable 的罪魁祸首。

解决方法:

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

关于javascript - Firebase 存储随机返回存储/取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52761303/

相关文章:

javascript - 如何使用 useEffect 更新函数(如 componentDidUpdate)并使用 .map 函数从 JSON 文件 ReactJS 显示

firebase - 方法 'setData' 没有为类型 'documentreference' 定义

java - 我应该如何获取文档字段并在另一个集合的另一个 map 中使用它们?

java - [CustomClassMapper] : No setter/field for . .. 在 Firebase Firestore 中的类中找到

ios - Firebase Storage putData 方法从不执行完成 block

firebase - 我可以将 Firebase "Resize Images"扩展用于特定的 Cloud Storage 文件夹吗?

javascript - jquery 重置追加()

javascript - 使用不符合路由要求的path twig函数生成url

javascript - json值的长度?

ios - 索引超出 Firebase 存储范围