title: Swift Firebase Storage - when updating data, image disappear from app
body: <p>I've got a problem with updating data. As you can see on this picture below, when I change those three textfields but leave current image and tap &quot;Save&quot;, it will update my data in Firebase but also will upload a NEW image which is EMPTY so user will see an empty UIImageView.</p>
  <p>Why is that?</p>
  <p><a href="https://i.stack.imgur.com/wr4yK.png" rel="nofollow noreferrer">Change Medication view image</a></p>
  <p><a href="https://i.stack.imgur.com/YiULj.png" rel="nofollow noreferrer">Change Medication view no image</a></p>
  <p>This is my method from Firebase to save image(data) and download URL:</p>
  <pre><code>func saveImageToStorage(cellImage: Data, completion: @escaping(Result&lt;String, Error&gt;) -&gt; Void) {
      guard let uid = Auth.auth().currentUser?.uid else { return }
      refStorage.child(uid).child(imageName).putData(cellImage, metadata: nil) { (_, error) in
          guard error == nil else {
              completion(.failure(NSError(domain: &quot;Saving image to storage failed&quot;, code: 0)))
              return
          }
          
          self.refStorage.child(uid).child(self.imageName).downloadURL { (url, error) in
              guard let url = url, error == nil else { return }
              let urlString = url.absoluteString
              completion(.success(urlString))
              print(&quot;URL downloaded: \(urlString)&quot;)
          }
      }
  }
  </code></pre>
  <p>Here is extension with UIImagePickerControllerDelegate:</p>
  <pre><code>extension CurrentMedicationSettingsViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  
  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
      let compressionQualityValue: CGFloat = 0.1
      
      let image = info[.originalImage] as? UIImage
      userMedicationSettingView.medicationImageView.image = image
      
      if let uploadData = image?.jpegData(compressionQuality: compressionQualityValue) {
          imageData = uploadData
      }
      
      picker.dismiss(animated: true, completion: nil)
  }
  </code></pre>
  <p>ViewModel where update medication method is:</p>
  <pre><code>  func updateMedicationInfo(data: Data, pillName: String, capacity: String, dose: String, childId: String, completion: @escaping () -&gt; Void) {
      firebaseManager.saveImageToStorage(cellImage: data) { (result) in
          switch result {
          case .failure(let error):
              print(error.localizedDescription)
          case .success(let url):
              self.firebaseManager.updateMedicationInfo(pillName: pillName, capacity: capacity, dose: dose, cellImageURL: url, childId: childId)
          }
          completion()
      }
  }
  </code></pre>
  <p>Thanks for any advice!</p>
  <p>Cheers!</p>