如何快速获取Firebase上图像的下载URL? [英] how to get the download url of an image on firebase in swift?

查看:38
本文介绍了如何快速获取Firebase上图像的下载URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新近快速使用Firebase.我正在尝试获取已经上传到Firebase存储中的图像的下载URL.我尝试了以下代码:

Newly working with firebase with swift. I'm trying to obtain the download url of an image that I already uploaded into firebase storage. 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'
  }
}

我想获取URL作为字符串.什么是好习惯?预先感谢.

I want to obtain the url as a string. What is a good practice? Thanks in advance.

推荐答案

如果要获取Url字符串而不是Url,则可以使用Url的 absoluteString 来获取字符串值./p>

if you want to get Url String instead of Url, then you can use absoluteString of the Url to get the String Value.

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
  }
}

这篇关于如何快速获取Firebase上图像的下载URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆