ios-Firebase存储URL检索或从Firebase数据库检索 使用Firebase存储方法storageReference.downloadURL()检索图像URL以检索URL:

ios-Firebase存储URL检索或从Firebase数据库检索 使用Firebase存储方法storageReference.downloadURL()检索图像URL以检索URL:,ios,firebase,firebase-realtime-database,firebase-storage,Ios,Firebase,Firebase Realtime Database,Firebase Storage,示例: storageDownloadReference(completion: { url in let imageURL = url } // Save the URL, after storing the image. ref.child("items").child(item).setValue(["imageURL": downloadURL]) // And then read the URL from the database: r

示例:

    storageDownloadReference(completion: { url in 
    let imageURL = url
    }
// Save the URL, after storing the image.

    ref.child("items").child(item).setValue(["imageURL": downloadURL])

// And then read the URL from the database:

    ref.child("items").child(item).observeSingleEvent(of: .value, with: { (snapshot) in
      let value = snapshot.value as? NSDictionary
      let imageURL = value?["imageURL"] as? URL ?? ""
  • 将图像上载到存储器并获取
    下载URL
    后,将URL保存在Firebase数据库中,以便以后检索
  • 示例:

        storageDownloadReference(completion: { url in 
        let imageURL = url
        }
    
    // Save the URL, after storing the image.
    
        ref.child("items").child(item).setValue(["imageURL": downloadURL])
    
    // And then read the URL from the database:
    
        ref.child("items").child(item).observeSingleEvent(of: .value, with: { (snapshot) in
          let value = snapshot.value as? NSDictionary
          let imageURL = value?["imageURL"] as? URL ?? ""
    
    将图像上载到Firebase存储后,建议使用哪种检索方法


    推荐哪个选项/效率更高?

    两者都不优越。我认为你应该尽最大努力满足你的应用程序的需求

    如果您需要客户端直接从一个URL下载,并且该URL对任何使用该URL的人都具有通用访问权限,那么就这样做

    如果您需要客户端应用进行自身身份验证,以检查用户是否能够使用下载文件,则使用SDK下载文件

    下载URL不受安全规则的影响,因此如果需要使用规则,请不要使用下载URL。如果你想让互联网上的任何人只要有这个URL就可以访问这个文件,那么就使用下载URL


    如果根据我在这里说明的标准这不重要,那么就做你认为最方便的事情。

    你是说你想使用下载URL下载文件吗?这应该非常简单。您遇到了什么问题?现在我正在使用Firebase存储方法(选项1)下载URL,但我不确定是否将URL存储在实时数据库中,稍后再检索会更快(或更推荐)。这就是我正在寻找的答案!在我的例子中,我需要使用downloadURL,因为图像是公开的,并且没有任何规则。谢谢