title: How to fetch a profile image from Firebase Storage of the user who posts a new post?
body: <p>I have an instagram-like app where there is a small user profile image above their image post in the main feed.</p>
  
  <p>I have figured out how to fetch the user profile image of the current user, but I cannot figure out how to fetch the user profile image of the person who added the post. Please see my code below. </p>
  
  <p>How do I fetch the user image who created the post?</p>
  
  <p>My Firebase Database structure is:
  [my app] > "posts" > post id > "description", "image", "title", "uid", "userName", "location"</p>
  
  <p>My Firebase Storage structure is:
  [my app] > "Users" > uid > "profile_pic.jpg"</p>
  
  <p>I am using Swift 3 and Firebase. </p>
  
  <p>Thank you for any advice!!</p>
  
  <pre><code>var eventPosts = NSMutableArray()
  
  
  @IBOutlet weak var eventPostsTableView: UITableView!
  
  @IBAction func logoTapped(_ sender: Any) {
  }
  
  func loadData() {
      FIRDatabase.database().reference().child("events").observeSingleEvent(of: .value, with: { (snapshot) in
          if let eventPostsDictionary = snapshot.value as? [String: AnyObject] {
              for post in eventPostsDictionary {
                  self.eventPosts.add(post.value)
              }
              self.eventPostsTableView.reloadData()
          }
      })
  
  }
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      self.eventPostsTableView.delegate = self
      self.eventPostsTableView.dataSource = self
  
      loadData()
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return self.eventPosts.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! EventTableViewCell
  
      // Configure the cell
      let event = self.eventPosts[indexPath.row] as! [String: AnyObject]
      cell.titleLabel.text = event["title"] as? String
      cell.userNameLabel.text = event["userName"] as? String
  
  
      if ("image" as? String) != nil {
          let user = FIRAuth.auth()?.currentUser
          let storage = FIRStorage.storage()
          let storageRef = storage.reference()
          let profilePicRef = storageRef.child("Users").child((user?.uid)!+"/profile_pic.jpg")
          profilePicRef.data(withMaxSize: 1 * 1024 * 1024, completion: { (data, error) -&gt; Void in
              if (error != nil) {
  
                  print("Unable to download image")
  
              } else {
  
                  if(data != nil)
                  {
                      print("User already has image")
                      cell.userProfileImageView.image = UIImage(data: data!)
                  }
              }
  
          })
      }
  
  
      if let imageFileName = event["image"] as? String {
          let imageRef = FIRStorage.storage().reference().child("images/\(imageFileName)")
          imageRef.data(withMaxSize: 2 * 1024 * 1024) { (data, error) -&gt; Void in
              if error == nil {
                  // Success
                  let image = UIImage(data: data!)
                  cell.flyerImageView.image = image
                  cell.flyerImageView.clipsToBounds = true
  
  
              } else {
                  // Error
                  print("Error downloading image: \(error?.localizedDescription)")
              }
          }
      }
  
      return cell
  }
  
  }
  </code></pre>