Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...