WEBPACK_IMPORTED_MODULE_1__ ion_native_file __。FileReader不是构造函数

时间:2018-04-22 20:12:46

标签: android cordova ionic-framework image-uploading filereader

我有这个片段,我一直在尝试将图像上传到Firebase服务器。我抛出一个错误。我该如何解决这个问题?

cordova.js:311 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_1__ionic_native_file__.FileReader is not a constructor
    at main.js:404
    at win (FileEntry.js:85)
    at Object.callbackFromNative (cordova.js:291)
    at <anonymous>:1:9

代码段:

 uploadimage() {
    var promise = new Promise((resolve, reject)=> {
      this.filechooser.open().then((url)=> {
        (<any>window).FilePath.resolveNativePath(url, (result)=> {
          console.log("This is the url: ---- :" +url +"    "   +" This is the result " +result);
          this.nativepath = result;
          (<any>window).resolveLocalFileSystemURL(this.nativepath, (res)=> {
            res.file((resFile)=> {
              var reader = new FileReader();
              reader.readAsArrayBuffer(resFile);
              reader.onloadend = (ent: any) => {
                var imgBlob = new Blob([ent.target.result], { type: 'image/jpeg'});
                var imgStore = this.firestore.ref('/profileimages').child(firebase.auth().currentUser.uid);
                imgStore.put(imgBlob).then((res)=> {
                  this.firestore.ref('/profileimages').child(firebase.auth().currentUser.uid).getDownloadURL().then((url)=> {
                    resolve(url);
                  }).catch((error)=> {
                    reject(error);
                  })
                }).catch((error)=> {
                  alert('Upload failed' + error);
                })
              }
            })
          })
        })
      })
    })
    return promise;
  }

0 个答案:

没有答案