title: Swift: Images rotated from portrait to landscape when loaded from Firebase
body: <p>Part of my iOS app uses Firebase Storage to store and load images taken/uploaded by the user.
  However, every time I upload a picture to Firebase in portrait orientation, when I retrieve it back from Firebase later on it comes in landscape orientation and thus displays incorrectly.</p>
  
  <p>I've read that Firebase stores metadata to determine the correct orientation of an uploaded picture but it doesn't seem to be working for me.</p>
  
  <p>Any one know how to get the orientation the image was uploaded in without manually having to rotate it within the app's code?</p>
  
  <p>Thanks! </p>
  
  <p>edit for code:</p>
  
  <p>Uploading:</p>
  
  <pre><code>        let imageMetaData = FIRStorageMetadata()
          imageMetaData.contentType = "image/png"
  
          var imageData = Data()
          imageData = UIImagePNGRepresentation(chosenImage)!
  
          let currentUserProfilePictureRef = currentUserStorageRef.child("ProfilePicture")
  
          currentUserProfilePictureRef.put(imageData, metadata: imageMetaData) { (metaData, error) in
              if error == nil {
                  let downloadUrl = metaData?.downloadURL()?.absoluteString
                  self.currentUserRef.updateChildValues(["profilePictureUrl": downloadUrl!])
                  if (chosenImage.size.width.isLess(than: (chosenImage.size.height))) {
                      self.currentUserRef.updateChildValues(["profilePictureOrientation": "portrait"])
                  }
                  else {
                      self.currentUserRef.updateChildValues(["profilePictureOrientation": "landscape"])
                  }
  
  
              } 
          }
  </code></pre>
  
  <p>Retrieving:</p>
  
  <pre><code>self.currentUserStorageRef.child("ProfilePicture").data(withMaxSize: 20*1024*1024, completion: {(data, error) in
                      var profilePicture = UIImage(data:data!)
  
                      if(profilePicture?.size.width.isLess(than: (profilePicture?.size.height)!))! {
                          if (pictureOrientation == "landscape") {
                              profilePicture = profilePicture?.rotated(by: Measurement(value: -90.0, unit: .degrees))
                          }
                      } else {
                          if (pictureOrientation == "portrait") {
                              profilePicture = profilePicture?.rotated(by: Measurement(value: 90.0, unit: .degrees))
                          }
                      }
  
                      self.buttonProfilePicture.setImage(profilePicture, for: .normal)
                      self.buttonProfilePicture.imageView?.contentMode = .scaleAspectFill
                  })
  </code></pre>