我在将图像上传到 Firebase 存储时遇到问题。我需要在 HTML 中有一个文件类型的输入对象。然后我需要为该输入选择的图像上传到我的项目的 firebase 存储。还有一种方法可以将该图像的位置存储在实时数据库中,以便以后可以访问吗?我该怎么做?
提前谢谢
最佳答案
要链接到数据库,请尝试以下操作:
var ref= firebase.database().ref("Uploads");
var storage = firebase.storage();
var pathReference = storage.ref('images/stars.jpg');
pathReference.getDownloadURL().then(function(url) {
ref.push().set({
imgurl: url
});
更多信息在这里:
https://firebase.google.com/docs/storage/web/download-files
https://firebase.google.com/docs/storage/web/upload-files
将其添加到存储后,您将能够使用getDownloadUrl()
获取url
,然后将其添加到数据库中:
Uploads
pushid
imgurl: url
关于Firebase 存储 - 将图像上传到 Firebase 存储并在实时数据库中创建指向该图像的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49287171/