0

Is there any way to store image data in a Firebase Database instead of adding it to Firebase Storage (maybe as a string then convert it when I need to use it)? This function adds the image data to my storage but I need to be able to call it when I call a specific document from my Database. Essentially, I want to use the image data like a field for my documents, or connect them some other way if possible. Thanks in advance.

func addImg(img: UIImage, name: String) {
        let storageRef = storage.reference()
        let artworkRef = storageRef.child("images/\(name)")
        
        let data = img.pngData()
        
        artworkRef.putData(data!, metadata: nil) { (_, err) in
            if err != nil {
                print((err?.localizedDescription)!)
                return
            }
        }
    }
phast
  • 188
  • 1
  • 2
  • 12
  • I think your question has already an [answer](https://stackoverflow.com/questions/57251507/what-is-the-best-practice-to-store-the-image-data-in-firestore). – Alex Mamo Feb 15 '22 at 13:42
  • 1
    It's generally not a good idea to store large binary data in Realtime Database. You're paying a lot more for not much added benefit. – Doug Stevenson Feb 15 '22 at 13:46
  • @AlexMamo That answer doesn’t say if I can add binary image data to the database. It just gives a yes/no answer with no explanation in my opinion. I’m looking to store data from an image chosen from an image picker. – phast Feb 15 '22 at 13:52
  • @DougStevenson I’m just having an extremely hard time figuring out how to store the data and call it from the database. I’m very new to Firebase and async in general. Any tips would be helpful! – phast Feb 15 '22 at 14:01

0 Answers0