Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尽管更改了数据库规则,但将文件上载到firebase存储时仍返回403错误_Javascript_Firebase_Google Cloud Storage_Firebase Security - Fatal编程技术网

Javascript 尽管更改了数据库规则,但将文件上载到firebase存储时仍返回403错误

Javascript 尽管更改了数据库规则,但将文件上载到firebase存储时仍返回403错误,javascript,firebase,google-cloud-storage,firebase-security,Javascript,Firebase,Google Cloud Storage,Firebase Security,我正在使用HTML和JS创建一个基本网页,将GIF上传到firebase存储中 这是我的密码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Upload gifs</title> </head> <body> <progress value="0" max=

我正在使用HTML和JS创建一个基本网页,将GIF上传到firebase存储中

这是我的密码:

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title>Upload gifs</title>
  </head>
  <body>
    <progress value="0" max="100" id="uploader">0%</progress>
    <input type="file" valu="upload" id="fileButton"></input>

  </body>
    <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-storage.js"></script>

    <script>
        var firebaseConfig = {
          apiKey: "",
          authDomain: "",
          databaseURL: "",
          projectId: "",
          storageBucket: "",
          messagingSenderId: "",
          appId: "",
          measurementId: ""
        };
    firebase.initializeApp(firebaseConfig);
    console.log(firebase);

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

    fileButton.addEventListener('change', function(e){
      var file = e.target.files[0];

      var storageRef = firebase.storage().ref('gifs/' + "123");

      storageRef.put(file);

      task.on('state_changed', 
        function progress(snapshot) {
            var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
            uploader.value = percentage;
        }
        ,
        function error(err) {

        }

      )
  })

    </script>
</html>

尽管如此,当我运行代码时,它返回一个403错误,表示它是禁止的。我不知道为什么,因为规则已经改变,允许访问数据库,但我仍然有这个问题。非常感谢您的帮助。

您将Firebase提供的数据库服务之一的安全规则与的规则混为一谈

您可以在此处找到云存储安全规则的文档:

在您的情况下,因为您的问题似乎表明您希望允许任何人读写,所以您应该按照以下方式编写云存储规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}