ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-10 14:47:13  阅读:278  来源: 互联网

标签: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存储:用户取消了上传/下载.”
名称

(……)
名称_

“FirebaseError”
serverResponse

空值
serverResponse_

空值

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

是取消可观察性的罪魁祸首.

解:

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

标签:javascript,firebase,firebase-storage
来源: https://codeday.me/bug/20190710/1424864.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有