Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

swift - Retrieve multiple photos under a node from Firebase Storage

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...