This question already has answers here:
Value of type 'StorageMetadata' has no member 'downloadURL'

(6 个回答)


3年前关闭。




我使用以下代码,但是当我更新代码和 Pod 时出现以下错误:


 static func uploadVideoToFirebaseStorage(videoUrl: URL, onSuccess: @escaping (_ videoUrl: String) -> Void) {
    let videoIdString = NSUUID().uuidString
    let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("posts").child(videoIdString)
    storageRef.putFile(from: videoUrl, metadata: nil) { (metadata, error) in
        if error != nil {
            ProgressHUD.showError(error!.localizedDescription)
            return
        }
        if let videoUrl = metadata?.downloadURL()?.absoluteString {
            onSuccess(videoUrl)
        }
    }
}

我该如何解决这个问题?

更新:

swift - StorageMetadata' 没有成员  'downloadURL'-LMLPHP

最佳答案

作为新版本删除了 StorageMetadata 上的 downloadURLs 属性。使用 StorageReference.downloadURL(completion:) 获取当前下载 URL。

// reference of the file that's you want to download
let ref = storageRef.child("simpleImage.jpg")

// get the download URL
ref.downloadURL { url, error in
  if let error = error {

  } else {
    // Here you can get the download URL for 'simpleImage.jpg'
  }
}

您可以从这里获得引用:https://firebase.google.com/support/release-notes/ios#5.0.0

关于swift - StorageMetadata' 没有成员 'downloadURL',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50546796/

10-12 13:18