André Oliveira
André Oliveira

Reputation: 1123

How to proper get the image URL after uploading it to Firebase 3.0 using Swift

i'm trying to display a image uploaded to Firebase Storage in my app, to do that i want to save the url to Firebase Database.

This is how i'm uploading to Firebase:

            let storageRef = FIRStorage.storage().reference()
            let imagesRef = storageRef.child("images/pato.png")

            let data  = UIImagePNGRepresentation(imageSelectorImage.image!)

            let uploadTask = imagesRef.putData(data!, metadata: nil, completion: { (metadata, error) in
                if(error != nil) {
                    print("Upload error")
                } else {
                    let downloadURL = metadata!.downloadURL()

                    print("\(downloadURL)")
                }
            })

In the downloadURL i'm getting something like this https://firebasestorage.googleapis.com/v0/b/mytestapp-5a7f.appspot.com/o/images%2Fpato.png?alt=media&token=7b080333-8671-4bc2-994f-2cc9a9b76178

I tested and i did managed to display this image from the URL in my App, the question i have is about this token that is in the URL, will this last forever? ( since if i try to access the image without the token a got nothing back. )

Is that the right url to save in Firebase Database?

Thanks in advance for any help.

Upvotes: 2

Views: 2080

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598775

The token in the download URL is just a randomly generated string that makes the URL unguessable. It will not expire nor is it tied to any specific user account.

For this reason the Firebase documentation doesn't focus on the token. It instead says that the download URL is a public-but-unguessable URL.

Upvotes: 3

Related Questions