Photo Swift iOS App: Performance and Storage Suggestions

I'm trying to develop an iOS app where users upload photos, can anyone suggest the best and most effective ways to solve storage and performance issues. Think about it, each user will upload about 300 photos per month (worst case scenario). My main idea was to use the Document Directory locally for storing images and then synchronizing with FireBase.

I am starting to develop applications in iOS, wanting to learn the best practices for launching my application.

thank

0
source share
1 answer

You can do it as follows:

1) Upload the file to the firebase repository and get the URL to download:

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 the URL of the uploaded photo to node user with FIRDatabase. It will look like this:

enter image description here

But these will be id messages, for example, instead of mediaRef10andmediaRef700

So, you will have links to photos in custom node, and you can easily get them with good performance.

+1
source

Source: https://habr.com/ru/post/1677504/


All Articles