swift3 - Swift 3 - How to download Profile Image from FireBase Storage -
i need on retrieving image firebase storage, learned how save cant download current user profile. here code far:
firauth.auth()?.createuserwithemail(email!, password: password!, completion: { (authdata, error) in if error == nil { if (password == "" || name == "" || email == "") { self.showalert("error", message: " please fill in blank") } if (password != confirm_password) { self.showalert("error", message: "password don't match") } } else { self.showalert("error", message: "please try again") } let filepath = "\(firauth.auth()!.currentuser!.uid)/\("userphoto")" var data = nsdata() let metadata = firstoragemetadata() //let imagename = nsuuid().uuidstring let storageref = firstorage.storage().referenceforurl("gs://storageurl") storageref.child(filepath).putdata(data, metadata: metadata){(metadata,error) in if let error = error { print(error.localizeddescription) return } if let profileimageurl = metadata?.downloadurl()?.absolutestring { let values : [string : anyobject] = ["name": name!, "email": email!, "profileimageurl": profileimageurl] self.userpost(values) } } }) } //save data in database func userpost(values: [string: anyobject]) { let ref = firdatabase.database().referencefromurl("https://databaseurl.firebaseio.com/") ref.child("users").childbyautoid().setvalue(values) }
so got far cant figure out how download user profile. here code user profilevc:
@iboutlet weak var profileimg: uiimageview! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. self.retrivedata() profileimg.image = uiimage(named: "ic_account_circle.png") imagepicker.delegate = self } func downloadprofilephoto() { let storageref = firstorage.storage().referenceforurl("gs://storageurl.com") let filepath = "\(firauth.auth()!.currentuser!.uid)/\("userphoto")" }
please help.....
you need download image data, , create image. should try this:
let storage = firstorage.storage() var reference: firstoragereference! reference = self.storage.referenceforurl("gs://appname.appspot.com/filepath") reference.downloadurlwithcompletion { (url, error) in let data = nsdata(contentsofurl: url!) let image = uiimage(data: data!) profileimg.image = image }
you should check firebase documentation https://firebase.google.com/docs/storage/ios/download-files
Comments
Post a Comment