上传照片并将其设置为个人资料照片-Angular 5 + Firebase

时间:2018-11-15 17:32:45

标签: javascript angular firebase

我创建了一种上传照片并将其设置为用户个人资料照片的方法。 它在本地工作,但是它没有在数据库中进行设置,因此当我刷新网页时,更改就消失了。

组件 从组件中,我将照片上传到firebase,获得了链接,并使用HTML进行了展示(有效)

  //Upload a new picture to the database as a profile picture
  uploadProfilePicture(event) {
    const id = this.auxAuth.uid + "_updatedPhoto";
    this.ref = this.afStorage.ref(id);
    this.task = this.ref.put(event.target.files[0]);
    this.downloadURL = this.task.downloadURL();
    let user = firebase.auth().currentUser;
    this.authService.updateProfilePicture(user, this.downloadURL);
  }

服务 从服务中,我尝试在Firebase中执行相同的操作,但是它不起作用

//Update the user's profile picture
  updateProfilePicture(user, url) {
    user
      .updateProfile({
        photoURL: url.value
      })
      .then(res => {
        this.flashMessage.show("UpdatedProfilePicture", {
          cssClass: "alert-success",
          timeout: 3000
        });
      })
      .catch(function(error) {
        this.flashMessage.show(error, {
          cssClass: "alert-danger",
          timeout: 3000
        });
      });
  }

我想我缺少的是在then中执行此操作,但是我并没有真正知道应该怎么做

0 个答案:

没有答案
相关问题