【发布时间】:2018-06-15 23:01:37
【问题描述】:
我正在处理存储火力库,我正在尝试获取 URL 并将其设置为变量,不幸的是我无法做到这一点,我的代码有问题。有人可以帮帮我吗?
这是错误:
firebase.js:1 Uncaught (in promise) 错误:Reference.push 失败:第一个参数在属性“PostUsers.ImageURL.i”中包含未定义
这是代码:
console.log('Nice, The file has been successfully uploaded to the Firebase storage!');
var DownloadURL = uploadTask.snapshot.downloadURL;
var Url_File = uploadTask.snapshot.ref.getDownloadURL().then(function (URL) {
return URL;
});
alert(Url_File);
uploadTask.snapshot.ref.getDownloadURL().then(function (downloadURL) {
console.log('File available at', downloadURL);
//Url_File = downloadURL;
});
//getting the publication time
var dayObj = new Date();
var day = dayObj.getDate();
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var month = monthNames[dayObj.getMonth()]
var year = dayObj.getFullYear();
var hour = dayObj.getHours();
var minutes = dayObj.getMinutes();
var seconds = dayObj.getSeconds();
var GlobalUserName = <%=Session["UserId"] %>;
firebase.database().ref('PostUsers/').push({
ImageURL: Url_File,
userAuthor: GlobalUserName,
day: day,
month: month,
year: year,
hour: hour,
minutes: minutes,
seconds: seconds
});
//console.log('the download Url of your file is: '+ downloadURL);
console.log('User post successfully added to realtime data bases');
});
我尝试了很多不同的方法,但是没有一个能正常工作。
提前致谢。
【问题讨论】:
标签: javascript firebase firebase-storage