简体   繁体   English

如何快速获取firebase上图像的下载网址?

[英]how to get the download url of an image on firebase in swift?

Newly working with firebase with swift.新近与 swift 的 firebase 合作。 I'm trying to obtain the download url of an image that I already uploaded into firebase storage.我正在尝试获取已上传到 firebase 存储的图像的下载 url。 I tried the following code:我尝试了以下代码:

    storageRef.downloadURLWithCompletion { (URL, error) -> Void in
  if (error != nil) {
    // Handle any errors
  } else {
    // Get the download URL for 'images/stars.jpg'
  }
}

I want to obtain the url as a string.我想以字符串形式获取 url。 What is a good practice?什么是好的做法? Thanks in advance.提前致谢。

if you want to get Url String instead of Url, then you can use absoluteString of the Url to get the String Value. 如果要获取Url String而不是Url,则可以使用Url的absoluteString获取字符串值。

storageRef.downloadURLWithCompletion { (URL, error) -> Void in
  if (error != nil) {
    // Handle any errors
  } else {
    // Get the download URL for 'images/stars.jpg'

    let UrlString = URL.absoluteString

   // you will get the String of Url
  }
}

在wsift中,“ downloadURLWithCompletion”似乎不再起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM