Javascript Firebase存储错误-不是一个函数
使用Javascript Firebase存储错误-不是一个函数,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,使用html/JS,我试图编写一个文件 我把这个放在html标题中: <head> <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-app.js"></script> <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-firestore.js"></
html/JS
,我试图编写一个文件
我把这个放在html
标题中:
<head>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-firestore.js"></script>
然后,当我尝试写入storgae时,在main.js
文件上:
var storageRef = firebase.storage().storage.ref()('me/' + file.name);
var task=storageRef.put(file);
task.on('state_changed',
function progress(snapshot){console.log(snapshot.bytesTransferred)},
function error(err){},
function complete(){});
我在控制台上遇到此错误:
firebase.storage is not a function
编辑:
Tried again and got same error with :
// Create a root reference
var storageRef = firebase.storage().ref();
// Create a reference to 'images/mountains.jpg'
var finalRef = storageRef.child('me/' + file.name);
finalRef.put(file).then(function(snapshot){
console.log('uploading');
});
像这样更改脚本main.js的位置
<script>
var config = {
apiKey: "xxx",
authDomain: "xxxx.firebaseapp.com",
databaseURL: "https://xxxx.firebaseio.com",
projectId: "xxxx",
storageBucket: "xxxx.appspot.com",
messagingSenderId: "xxxxx"
};
firebase.initializeApp(config);
const db = firebase.firestore();
db.settings({timestampsInSnapshots:true});
</script>
//to here
<script src="javascripts/main.js"></script>
变量配置={
apiKey:“xxx”,
authDomain:“xxxx.firebaseapp.com”,
数据库URL:“https://xxxx.firebaseio.com",
投影:“xxxx”,
storageBucket:“xxxx.appspot.com”,
messagingSenderId:“xxxxx”
};
firebase.initializeApp(配置);
const db=firebase.firestore();
db.settings({timestampsInSnapshots:true});
//到这里
像这样更改脚本main.js的位置
<script>
var config = {
apiKey: "xxx",
authDomain: "xxxx.firebaseapp.com",
databaseURL: "https://xxxx.firebaseio.com",
projectId: "xxxx",
storageBucket: "xxxx.appspot.com",
messagingSenderId: "xxxxx"
};
firebase.initializeApp(config);
const db = firebase.firestore();
db.settings({timestampsInSnapshots:true});
</script>
//to here
<script src="javascripts/main.js"></script>
变量配置={
apiKey:“xxx”,
authDomain:“xxxx.firebaseapp.com”,
数据库URL:“https://xxxx.firebaseio.com",
投影:“xxxx”,
storageBucket:“xxxx.appspot.com”,
messagingSenderId:“xxxxx”
};
firebase.initializeApp(配置);
const db=firebase.firestore();
db.settings({timestampsInSnapshots:true});
//到这里
您还需要添加以下内容:
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-storage.js"></script>
为此:
var storageRef = firebase.storage().ref('me/' + file.name);
查看此项了解更多信息:
您还需要添加以下内容:
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-storage.js"></script>
为此:
var storageRef = firebase.storage().ref('me/' + file.name);
查看此项了解更多信息:
谢谢修复了它-没有帮助,上传时出现了相同的错误。我也阅读了文档,编辑了我的问题,然后再试一次,仍然是相同的错误。我必须导入一些东西到main.js文件吗?你也需要添加这个
是的!那救了我。也许你应该把这个加到你的答案里。谢谢。谢谢修复了它-没有帮助,上传时出现了相同的错误。我也阅读了文档,编辑了我的问题,然后再试一次,仍然是相同的错误。我必须导入一些东西到main.js文件吗?你也需要添加这个
是的!那救了我。也许你应该把这个加到你的答案里。谢谢