0

我想提供一个功能,用户可以查看他们上传的所有图像。在我的 Firebase 存储中,它在/$uid/image文件夹中包含用户的图像。

/$uid/image/imageA.png
/$uid/image/imageB.png
/$uid/image/imageC.png

但是,我不知道如何获取完整用户文件的参考。我尝试了下面的代码来下载它,但我得到了一个storage/object-not-found错误代码。

var imageRef = storageRef.child('UserImage/'+ user.uid + '/image');

我只想获取 Json 格式的图像下载 url 列表。例如,

{$uid/image:[
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX1',
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX2',
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX3'
]}
4

1 回答 1

0

首先确保您在这里没有遗漏“/”:

var imageRef = storageRef.child('UserImage/'+ user.uid + 'image');
                                                    here ^

还要确保在引用 ( /image.png) 末尾包含实际文件,而不是图像的用户子树。

使用这个功能:

imageRef.getDownloadURL().then(function(url) {
    // Get the download URL for '<reference>'
    // store the url, do something with it
}).catch(function(error) {
    // Handle any errors
});

然后,您可以将这些添加到数组或您喜欢的任何内容中。

参考:getDownloadURL()

于 2016-06-08T13:33:02.893 回答