显示Firebase中存储的所有图像

时间:2017-02-26 12:41:04

标签: jquery firebase firebase-realtime-database firebase-storage

我想在桌面上显示 Firebase存储空间中的所有图片。我似乎很难在 JavaScript 中这样做。它给了我一个错误:

  

Firebase存储:对象'Item_Images /'不存在。

vendor/bin/phpunit:2: no such file or directory: ?php
vendor/bin/phpunit:3: permission denied: /Applications
vendor/bin/phpunit:4: command not found: Homestead.yaml
vendor/bin/phpunit:5: command not found: Homestead.yaml
vendor/bin/phpunit:7: parse error near `\n'

HTML

var fbRef = firebase.database().ref().child("Item Posts");
var storage = firebase.storage().ref();
var storageRef = storage.child("Item_Images/");

fbRef.on("child_added", snap => {
    var name = snap.child("ItemName").val();
    var price = snap.child("Price").val();
    var category = snap.child("Category").val();
    var description = snap.child("Description").val();
    var image = storageRef.getDownloadURL().then(function(url){
        var test = url;
        document.querySelector('img').src = test;
    })

    $("#tableBody").append("<tr><td>" + image + "</td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>" );
});

这是我的数据库:

database

这是我当前的HTML表格:

HTML Table

1 个答案:

答案 0 :(得分:1)

呃..事实证明我已经自己解决了这个问题。我将在这里发布答案,这样可以帮助其他人。

var fbRef = firebase.database().ref().child("Item Posts");
//removed the storage reference

fbRef.on("child_added", snap => {
    var name = snap.child("ItemName").val();
    var price = snap.child("Price").val();
    var category = snap.child("Category").val();
    var description = snap.child("Description").val();
    //got the string URL from the database
    var image = snap.child("Image").val();

    //concatenated the img tag using the image variable at the top
    $("#tableBody").append("<tr><td><img src=" + image + "/img></td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>" );
});