Firebase SWIFT and Storage Image Gallery

Asked

Viewed 212 times

0

Good afternoon, I’m finishing a APP developed in Swift 4, with Xcode 9 and Firebase. I can already log in with Firebase, and e-mail through my App, what I need to do, which I’m not getting at all is how to set up an image gallery, with the images I record in the Firebase Storage, but this automatically, I can already upload the images to Firebase Storage. Follow what I want to do, I’m 3 weeks trying and reading various tutorials more can not.

Whereas the images are already in Firebase Storage:

  1. List in an image gallery, all user-saved photos in Firebase Storage;
  2. This list has to be thumbnails of the images, and when clicking they are in the normal size that are saved.

Note: There is this library that assembles the image gallery, the way I want, but I do not know how to use and nor how I would load the images automatically from Fisebase ( library:https://github.com/mwaterfall/MWPhotoBrowser) Could you help me please.

Thank you

  • 1

    Firebase Storage doesn’t have a way to show all the images that are stored there. What you have to do is save the list of images in your Database. This makes it easier to list them

1 answer

0

Opa, blza!?

What I did was this: every time I uploaded an image, I recorded in the user profile the path the photo was saved:

    func uploadImage() -> Void {
    let storage = Storage.storage()
    let nomeImagem = self.nome + ".jpg"
    let storageRef = storage.reference().child("App/Usuarios").child(userID).child("ImagemPerfil").child(nomeImagem)
    let metadata = StorageMetadata()
    metadata.contentType = "image/jpeg"

    if let uploadData = UIImageJPEGRepresentation(self.imagemPerfil.image!, 0.2){
        storageRef.putData(uploadData, metadata: metadata, completion: { (metadata, error) in
            if error == nil{
                storageRef.downloadURL { url, error in
                    if error != nil {
                        // Handle any errors
                    } else {
                        self.mEleitorModel.urlFotoPerfil = url?.absoluteString
                        self.gravaUsuario()
                    }
                }
            }
        })
    }
}

saved the user with the image path, in your case you can create a list with the images attached to the user:

to upload the image, turn the view on your code and do the following (this Cod there leaves it round, if you do not want to remove):

    func carregaImagem() -> Void {
    let url = URL(string: mCandidato.urlFotoPerfil!)
    let data = try? Data(contentsOf: url!)
    imagemPerfil.image = UIImage(data: data!)
    imagemPerfil.layer.borderWidth = 1.0
    imagemPerfil.layer.masksToBounds = false
    imagemPerfil.layer.borderColor = UIColor.white.cgColor
    imagemPerfil.layer.cornerRadius = imagemPerfil.frame.size.width / 2
    imagemPerfil.clipsToBounds = true
}

To add a list of images, create a url dictionary, and already send the firebase dictionary. If it is a list of images, just put one for before carrying them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.