在ionic和firebase上上传图片

时间:2018-11-17 01:25:50

标签: firebase ionic-framework

在ionic上的浏览器上上传图像工作正常,但在本机(iOS和android)上无法正常工作。任何帮助,将不胜感激。非常感谢。

uploadImage() {
const loader = this.commonService.showLoader();
let storageRef = firebase.storage().ref();
let file;
file = (<HTMLInputElement>document.getElementById('inputFileProfile')).files[0];
storageRef.child('users/' + localStorage.getItem('uid') + '/profile/' + file.name)
  .put(file, { contentType: 'image/*' })
  .then(res => {
    storageRef.child('users/' + localStorage.getItem('uid') + '/profile/' + file.name).getDownloadURL()
      .then(url => {
        setTimeout(() => {
          this.dbService.getUserById(localStorage.getItem('uid')).update({ profilePic: url, profilePicThumb: null })
            .then(res => {
              this.commonService.showToast('Image has been Changed!');
              loader.dismiss();
            });
        }, 4000);
      }).catch(error => {
        this.commonService.showToast(error.message);
        loader.dismiss();
      });
  }).catch(error => {
    this.commonService.showToast(error.message);
    loader.dismiss();
  });

0 个答案:

没有答案