【问题标题】:How can i download a file which contain images? [duplicate]如何下载包含图像的文件? [复制]
【发布时间】:2016-10-08 19:12:16
【问题描述】:

我想提供一个功能,用户可以查看他们上传的所有图像。在我的 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'
]}

【问题讨论】:

标签: javascript firebase firebase-storage


【解决方案1】:

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

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()

【讨论】:

  • 我已经使用了这个,所以我可以捕获错误然后在控制台中记录错误代码..
  • 然后抓取成功传入的url,并检查以确保您的路径正确。我已经编辑了我的答案
  • 我收到了一个错误,它是 storage/object-not-found。另外,我的路径应该是正确的,因为如果我尝试使用UserImage/'+ user.uid + '/image/' + 'imageA.png',它会没事的。
  • @theblindprophet 实际文件?这是否意味着我无法从 firebase 下载文件夹?
猜你喜欢
  • 1970-01-01
  • 2011-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-27
  • 2013-05-29
  • 1970-01-01
相关资源
最近更新 更多