从Firebase存储中的节点下检索多张照片 [英] Retrieve multiple photos under a node from Firebase Storage

查看:108
本文介绍了从Firebase存储中的节点下检索多张照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CollectionView,我正在使用来自Firebase存储的图像来填充。我将图像存储在'userId'节点下。我想检查在节点下可用的批量文件,所以我可以将它们存储在一个数组中。



我试图单独检索每个URL但是,我认为这是一个非常错误的做法。但是,我不知道如何以最有效的方式做到这一点,以及在哪里放置 collectionView.reload()。这就是我所做的:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' gs:storageUrl)。child(uid).child(profile.jpg)

firstImageRef.downloadURLWithCompletion {(URL,error) - >如果(错误!=无){
print(error)
} else {
if $ url = URL {
self.databaseImagesOrder.append(url )
}
}
}

let secondImageRef = storage.referenceForURL(gs:storageUrl)。child(uid).child(second_pic.jpg )
secondImageRef.downloadURLWithCompletion {(URL,error) - >如果(错误!=无){
print(error)
} else {
if $ url = URL {
self.databaseImagesOrder.append(url )
}
}
}

// etc ..

collectionView.reloadData()

另外,更好地获取图像作为NSData更好地获取网址,然后获取图像?如果是这样,我怎么能从Firebase存储批量检索图像?

解决方案

目前没有批量或批量上传/从Firebase存储 - 我认为这里有太多的问题:我们将文件压缩和存储,我们会返回一个压缩包,等等。 / p>

我们解决上载和下载多个文件问题的解决方案是单独上传并将URL存储在另一个数据库(例如Firebase实时数据库)中,然后您可以将其同步并单独下载每个文件(或者存储下载文件并使用 SDWebImage 等工具下载或缓存相应的URL)。

请参阅 https://gist.github.com/mcdonamp/cc45567cd95ba2a62017cb21e891effd https://www.youtube.com/watch?v=xAsvwy1-oxE&feature=youtu.be 我们如何做到这一点的例子。


I have a CollectionView that I am using images from Firebase Storage to fill. I store the images under 'userId' node. I want to check the files existence in bulk that are available under the node, so I can store them in an array.

I tried to retrieve the urls separately for each one, however, I believe this is a very wrong approach. But, I couldn't figure out how to do it in most efficient way and where to put collectionView.reload(). This is what I did:

let storage = FIRStorage.storage()
let firstImageRef = storage.referenceForURL("gs:storageUrl").child(uid).child("profile.jpg")

firstImageRef.downloadURLWithCompletion { (URL, error) -> Void in
   if (error != nil) {
       print(error)
   } else {
       if let url = URL {
         self.databaseImagesOrder.append(url)
       }
   }
}

let secondImageRef = storage.referenceForURL("gs:storageUrl").child(uid).child("second_pic.jpg")
secondImageRef.downloadURLWithCompletion { (URL, error) -> Void in
   if (error != nil) {
      print(error)
   } else {
      if let url = URL {
        self.databaseImagesOrder.append(url)
      }
   }
 }

 // etc.. 

 collectionView.reloadData()

Also, is it better to fetch the image as NSData better than fetching the urls first and then fetching the images? If so, how can I retrieve images in bulk from Firebase Storage?

解决方案

Currently there's no bulk or batched upload/download to/from Firebase Storage--I think there are too many question here: would we zip the files up and store them that way, would we returned a zipped bundle, etc. Would we just return an array of download URLs, or appropriate data?

Our solution to the problem of listing and downloading multiple files is to upload them individually and store the URLs in another database (say the Firebase Realtime Database), which you can then sync and use to download each file individually (or you store the download files and use a tool like SDWebImage to download or cache the appropriate URLs).

See https://gist.github.com/mcdonamp/cc45567cd95ba2a62017cb21e891effd and https://www.youtube.com/watch?v=xAsvwy1-oxE&feature=youtu.be for an example of how we did this.

这篇关于从Firebase存储中的节点下检索多张照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆