UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to save multiple images to firebase storage from the same user?

Forums > Swift

In my app user presses the button to take the photo and then it uploads to firebase storage but every time I do a new photo the old one disappears and it replaces itself with the same url string as old one had before. How can I upload a new image every time the same user takes and uploads the photo?

Here is the code

let storage = Storage.storage().reference()
    guard  let imageData = ecoImage.jpegData(compressionQuality: 0.75) else {
        return
    }

    let metaData = StorageMetadata()
    metaData.contentType = "image/jpg"

        storage.child("pins/\("Eco1")").putData(imageData, metadata: metaData) { (meta, error) in
            if let err = error {
                print(err.localizedDescription)
            } else {
                storage.child("pins/\("Eco1")").downloadURL { (url, err) in
                    if let e = err {
                        print(e.localizedDescription)
                    } else {
                        let urlString = url?.absoluteString
                        doc.setData(["uid": uid, "pinLocation": ecoPin, "time": timeData, "url": urlString!]) { (error) in
                            if error != nil {
                                print(error?.localizedDescription)
                                return
                            } else {
                                print("Pin saved")
                            }
                        }
                    }
                }
            }
             print("Image sent")
        }

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.