我正在創(chuàng)建一個使用 HTML 和 JS 將 gif 上傳到我的 firebase 存儲的基本網(wǎng)頁。這是我的代碼:<!DOCTYPE html><html> <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>我的 firebase 數(shù)據(jù)庫規(guī)則是:rules_version = '2';service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if true; } }}盡管如此,當(dāng)我運行代碼時,它返回一個 403 錯誤,說明它被禁止。我不確定為什么規(guī)則已更改為允許訪問數(shù)據(jù)庫,但我仍然有問題。將不勝感激任何幫助。
盡管更改了數(shù)據(jù)庫規(guī)則,但將文件上傳到 Firebase 存儲仍會返回 403 錯誤
白板的微信
2022-06-16 15:49:35