Reputation: 2261
I am following Google's guide for getting an image from the storage and then placing it into an imageView using "FirebaseStorageUI", which seems to use SDWebImage.
I have the problem that the image simply is not set. There are no errors in the console. My code:
@IBOutlet weak var imageView: UIImageView!
var ref = FIRDatabase.database().reference()
var storageRef = FIRStorage.storage().reference()
override func viewWillAppear(_ animated: Bool) {
self.getHouseID(){ (houseName) -> () in
if houseName.characters.count > 0 {
self.houseIDLabel.text = houseName // does work correctly
let photoRef = self.storageRef.child("\(houseName)/\("housePhoto.jpg")")
self.housePhotoImageView.sd_setImage(with: photoRef) // not working
} else {
print("error while setting image and house name label")
}
}
}
My Storage looks like this:
The label gets correctly set with the houseName
, which is also used in the storage path to retrieve the image. Anything I have missed here?
Upvotes: 1
Views: 399
Reputation: 3272
1. I think the problem is that your awesomehouse/
has a slash in the end.
Try to check which child()
your are creating: awesomehouse
or awesomehouse/
2. The second possible problem is that you are trying to fetch "housePhoto.jpg"
instead of stored housePhoto
.
So, it should be:
let photoRef = self.storageRef.child("awesomehouse/").child("housePhoto")
self.housePhotoImageView.sd_setImage(with: photoRef) // should work now
Or it better to save photo to storage with extension ".jpg"
, then it would be:
let photoRef = self.storageRef.child("awesomehouse/").child("housePhoto.jpg")
self.housePhotoImageView.sd_setImage(with: photoRef) // should work now
Try both. I think it will solve your problem.
Hope it helps
Upvotes: 1
Reputation: 8020
My first guess would be that you are not setting this on the main queue.
Try this:
DispatchQueue.main.async {
self.housePhotoImageView.sd_setImage(with: photoRef)
}
I don't know if it matters that your image file does not have a file extension, that might also be worth trying. Hope this helps
Upvotes: 1