0

I am trying to develop an iOS application where users upload photos, can someone please suggest best and efficient ways to handle the storage and performance issues. Consider each user will be uploading around 300 photos in a month (worst case scenario). My basic idea was to use Document Directory locally to store images and then sync it with FireBase.

I am a beginner in developing apps in iOS, willing to know the best practices to start my app.

Thank you

Jarvis
  • 163
  • 1
  • 13
  • Btw i checked your profile. You have asked 13 questions. And accepted 0. If answer helped, you should accept it (tap jackdaw) and uparrow it. Because we spend time for you and getting nothing from it. And no one can be sure, that answer helped. Thank you – Vlad Pulichev May 12 '17 at 12:17
  • 1
    Thank you for letting me know about the jackdaw! I do uparrow always but it wouldnt be public unless my profile hits 125 reputations. – Jarvis May 12 '17 at 16:04

1 Answers1

1

You can do it next way:

1) Upload file to firebase storage and get download url for it:

static func upload(_ image: UIImage,
                  completion: @escaping (_ hasFinished: Bool, _ url: String) -> Void) {
let data: Data = UIImageJPEGRepresentation(image, 1.0)!

// ref should be like this
let ref = FIRStorage.storage().reference(withPath: "media/" + userId + "/" + unicIdGeneratedLikeYouWant)
ref.put(data, metadata: nil,
                   completion: { (meta , error) in
                    if error == nil {
                       // return url
                       completion(true, (meta?.downloadURL()?.absoluteString)!)
                    } else {
                       completion(false, "")
                    }
  })

Then save url of the uploaded photo to user node with FIRDatabase. It will look like:

enter image description here

But it will be posts ids for example instead of mediaRef10 and mediaRef700

So, you will have in user node links to photos and you can easy get them with good perfomance.

Vlad Pulichev
  • 3,162
  • 2
  • 20
  • 34