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:

  • The request was denied by service delegate (SBMainWorkspace)
  • Properly Using Firebase Cloud Functions and Stripe
  • Topic Won't Save in Firebase
  • Swift Firebase Snapshot to object model
  • Firebase with Swift ambiguous use of observeEventType
  • Sending IOS notifications from Firebase (or another platform) to specific terminales
  • 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?

    Solutions Collect From Internet About “Retrieve multiple photos under a node 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.