Firebase上传用户图像错误

时间:2018-07-12 07:16:27

标签: javascript angularjs firebase upload firebase-storage

嗨,我需要您的帮助。我不断收到此错误

  

开机自检   https://firebasestorage.googleapis.com/v0/b/talknote-48adf.appspot.com/o?name=%5Bobject%20Object%5D%2FprofilePicture%2F02.jpg   403()

我被困在这里两天了,我真的需要你的帮助。有什么办法可以解决这个问题。

这是我的代码:

 var uploader = document.getElementById('uploader');
      var fileButton = document.getElementById('fileButton');

  //Listen for file 
  fileButton.addEventListener('change', function(e){

     //Get File
     var file = e.target.files[0];

     // Get current username
     var user = firebase.auth().currentUser;

     //Create a Storage Ref
     var storageRef = firebase.storage().ref(user + '/profilePicture/' + file.name);

     //Upload file
     var task = storageRef.put(file);     

     //Update Progress Bar 
     task.on('state_changed', 

     function progress(snapshot){
        var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) *100;
        uploader.value = percentage;

        //if percentage = 100
        //$(".overlay").hide();         
     },

     function error(err){

     },

     function complete(){

     }

   );           
});

这是firebase规则:

service firebase.storage {
  match /b/talknote-48adf.appspot.com/o {
    match /{userId}/profilePicture/{fileName} {
      // Anyone can read
      allow read;
      // Only the user can upload their own profile picture
      // Profile picture must be of content-type "image/*"
      allow write: if request.auth.uid == userId
                   && request.resource.contentType.matches('image/.+');
    }
  }
} 

0 个答案:

没有答案