问题
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
回答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:
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.
来源:https://stackoverflow.com/questions/43926284/ios-swift-app-with-more-photos-performance-and-storage-suggestions