如何更新用户配置文件节点(Web)

时间:2016-10-04 20:46:31

标签: javascript firebase firebase-realtime-database

我创建了使用Firebase电子邮件身份验证的用户,并将用户配置文件数据存储在用户节点中的Firebase数据库中,并且子项是UID。

像这样的东西

users:
      UID: 
          DisplayName: "A name"
          DisplayPic:"Firebase DownloadURL"
          DisplayTerms:"on"
          DsiplayEmail:"enail@mail.com"

因此,我希望通过将图片上传到Firebase存储并更新DisplayPic节点中的DownloadURL值,让用户可以选择更改其个人资料图片。

我正在尝试这样的事情:

 /*************uploadImage************/
//get variables
var filebutton = document.getElementById('filebutton');

//listen for file selction
filebutton.addEventListener('change', function(e){
   //get the file
   var file = e.target.files[0];



    var metadata = {
        'contentType': file.type
      };

   var storageRef = firebase.storage().ref('userProfilePic/' + file.name).put(file, metadata).then(function(snapshot){
//savr image url to db
   var url = snapshot.metadata.downloadURLs[0];
// Get a key for a new onject.
   var user = firebase.auth().currentUser;

  firebase.database().ref().child(user.uid).child('DisplayPic').push( {
      DisplayPic:userpic=url,
  });

但我获得了许可拒绝错误。

这是我的规则:

 "users": {
      "$uid": {
        // grants write access to the owner of this user account whose uid must exactly match the key ($uid)
        ".write": "$uid === auth.uid",
        // grants read access to any user who is logged in with an email and password
        ".read": "$uid === auth.uid"
      }

    }

图片上传正确,但DisplayPic节点未更新。有什么想法吗?

0 个答案:

没有答案
相关问题