2

I currently am uploading and downloading images off of Firebase. I store the URL as a string in the variable profilePicture and then use a URL session to download the image. However, every time the photo loads in sideways. However, when I initially pick the picture form the camera roll, it is shown the correct way. Any ideas of what might be happening?

Uploading Image: When I upload the image, once it is completely saved, I set the URL to the variable profilePicture.

    var storageRef : FIRStorageReference = FIRStorageReference()
    if let uid = currentUser?.uid {
        storageRef = FIRStorage.storage().reference().child("\(uid).png")
    }

    if let uploadData = UIImagePNGRepresentation(profilePictureImageView.image!) {

        let uploadTask = storageRef.put(uploadData, metadata: nil) { snapshot, error in
            if let error = error {
                print(error)
            }
        }

        // Shows progress bar until saved
        uploadTask.observe(.progress) { snapshot in
            self.progressBar.observedProgress = snapshot.progress
            self.progressBar.isHidden = false;
        }

        uploadTask.observe(.success) { snapshot in
            if let profileImageURL = snapshot.metadata?.downloadURL()?.absoluteString {
                self.user?.profilePicture = profileImageURL
                self.progressBar.isHidden = true;
                self.savedLabel.isHidden = false

            }
        }
    }

Downloading Image:

 if let profileImageURL = user?.profilePicture {
        if let url = URL(string: profileImageURL) {
            URLSession.shared.dataTask(with: url, completionHandler: { (data, response, error) in

                if error != nil {
                    print(error!)
                    return
                }

                DispatchQueue.main.async {
                    self.profilePictureImageView.image = UIImage(data: data!)
                    self.activityIndicator.stopAnimating()
                }
            }).resume()
        }
    }
AL.
  • 36,815
  • 10
  • 142
  • 281
Sarah
  • 107
  • 1
  • 8

1 Answers1

0

I have a feeling it has to do with image orientation issues, rather than anything in Firebase land. Something like iOS Image Orientation has Strange Behavior

Community
  • 1
  • 1
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49