从角度上传Firebase云存储上的无效参数错误

时间:2018-07-01 10:33:16

标签: angular firebase firebase-storage

这是我尝试从有角度的应用程序将pdf上传到Firebase云存储时遇到的错误。

Error: Uncaught (in promise): t: {"code_":"storage/invalid-argument","message_":"Firebase Storage: Invalid argument in `on` at index 0: Expected one of the event types: [state_changed].","serverResponse_":null,"name_":"FirebaseError"}

在component.html

<input type="file" (change)="fileChange($event)" placeholder="Upload file" accept=".pdf,.doc,.docx">

fileChange函数

fileChange(event)
  {
    console.log("event received to the component is ",event);
    this.certificate = event.target.files[0];
    console.log("files received to the component is ",this.certificate);
  }

云存储的内部服务

  private storage = firebase.storage();

  uploadCertificate(certificate)
  {
    console.log("certificate received to cloud storage service is ",certificate);
    let storageRef = this.storage.ref('certificates/'+certificate.name);
    let task = storageRef.put(certificate)
    return new Promise((resolve,reject)=>{
     task.on('state_change',
       function progress(snapshot:any)
       {
         var percentage = (snapshot.bytesTransferred/snapshot.totalBytes)*100;
         console.log(percentage + " percentage");
       },
       function error(err)
       {
         console.log("error in uploading certificate ",err);
         reject(err);
       },
       function complete()
       {
         console.log("upload complete");
         resolve()
       }
     )
    })

Log of the Data being passed to the function

0 个答案:

没有答案