0

I'm trying to implement a feed for images using Firebase Storage, think of it like the Instagram photo feed. My Problem:

  • I don't know how many images there are in my Firebase reference folder
  • I want only the images to be shown that have been taken, let's say in the last week

I tried downloading the images from the reference like this:

let storageRef = storage.reference()


    for i in 0...10 {

        let imageRef = storageRef.child("images/" + String(i) + ".jpg")

        imageRef.dataWithMaxSize((10 * 1024 *  1024), completion: { (data, error) -> Void in
            if (error != nil) {
                print(error)
            } else {
                let image: UIImage! = UIImage(data: data!)
                self.downloadedPhotos.append(image) //downloadedPhotos is an array of UIImages

                self.configureFeed() //takes care of some UI

            }
        })
    }

Here I run into the obvious problem: I've only downloaded 10 images, called "1","2",..., "10"

  • What kind of way to name the images when users upload them would you suggest?
  • How could I keep track of how many images there are?
  • How could I delete those images from the reference that are older than a week?
  • Should I use Image Cashing Libraries like Kingfisher or would you go with the above style?

Thank you guys really much for any help!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Elio_
  • 398
  • 4
  • 13

1 Answers1

1

Let's handle these one at a time:

  • What kind of way to name the images when users upload them would you suggest?

I'd take a look at the many other questions like this: Retrieving image from Firebase Storage using Swift

  • How could I keep track of how many images there are?

See above.

  • How could I delete those images from the reference that are older than a week?

You can use Object Lifecycle Management to delete images after a certain time. Deleting them from the database would be harder--maybe an integration with Google Cloud Functions GCS notifications could sync this.

  • Should I use Image Cashing Libraries like Kingfisher or would
    you go with the above style?

I totally recommend using an image loader like SDWebImage or PINRemoteImage after pulling the download image from the realtime database.

Community
  • 1
  • 1
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49
  • Thanks for your help, looking forward to dive into these technics. – Elio_ Sep 12 '16 at 07:13
  • Really happy it worked out indeed. The combination of Storage and using a downloadURL stored in the realtime database made it all work out. Thank you really much for the provided links. – Elio_ Sep 12 '16 at 19:34