Firebase Storage store metadata url in realtime database and use it asynchronous download image and cache it

228 views
Skip to first unread message

Saran

unread,
Jun 8, 2016, 11:50:55 PM6/8/16
to Firebase Google Group
Hi, 

I am using IOS SDWebimage library to asynchronous download image and cache it. I would like to know if below method is the right way to do it.


    func storeUserPic(uid: String, data: NSData)
    {
        let filePath = REF_STORAGE.child(“user/test.jpeg")
        let metaData = FIRStorageMetadata()
        metaData.contentType = "image/jpeg"
        
        filePath.putData(data, metadata: metaData) { (meta, error) in
            if let error = error
            {
                print(error.localizedDescription)
                return
            }
            else
            {
                self.REF_USERS.child(uid).updateChildValues([“testpic” : meta!.downloadURLs![0].absoluteString])
            }
        }
        
    }

Now when i refer to the user uid i will be able to use the URL and hence SDWebimage to display it.

Mike Mcdonald

unread,
Jun 9, 2016, 12:51:36 AM6/9/16
to Firebase Google Group
Saran,

This would be one way of storing the download URL (in the database) and making it accessible to SDWebImage for download. We're working on an extension to SDWebImage to allow Firebase Storage references to be "downloaded" directly in SDWebImage, which would potentially eliminate the need for you to store a public download URL at all :)

Thanks,
--Mike

Saran

unread,
Jun 9, 2016, 10:39:57 AM6/9/16
to Firebase Google Group
Thank you Mike :)
Reply all
Reply to author
Forward
0 new messages