I am trying to get an image that I have stored inside Firebase Storage inside an UIImageView. I have the URL of the image saved inside Firebase Database for that user, but don't know how to grab it
Asked
Active
Viewed 451 times
-1
-
Read this answer: https://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift/27517280#27517280 – Alan Scarpa Jan 03 '19 at 22:21
-
Possible duplicate of [Loading/Downloading image from URL on Swift](https://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift) – Alan Scarpa Jan 03 '19 at 22:21
2 Answers
0
you need to make an action for it this func opens the Photo carrier
@IBAction func selecFoto(_ sender: UIButton) {
let imageController = UIImagePickerController()
imageController.delegate = self
imageController.sourceType = UIImagePickerController.SourceType.photoLibrary
//you can also set animate to false
self.present(imageController, animated: true, completion: nil)
}
this func selects the image and you can storage wherever you want
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// here you can preview the image you selected if that's the case
imageView.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}

José Raúl Toledano R
- 327
- 5
- 14
0
import FirebaseStorage
Storage.storage().reference(forURL: yourDownloadedURL).getData(maxSize: 1048576, completion: { (data, error) in
guard let imageData = data, error == nil else {
return
}
someImageView.image = UIImage(data: imageData)
})
Obviously, handle errors as well as corrupted image data, by perhaps falling back to a default image (just because we have image data in hand does not guarantee it will render a perfect image), and use a maximum file size appropriate to your application.

trndjc
- 11,654
- 3
- 38
- 51