gpt4 book ai didi

ios - 从 firebase 存储下载文件名

转载 作者:行者123 更新时间:2023-11-28 08:00:21 25 4
gpt4 key购买 nike

正如我在文档中所读到的,我可以像这样访问 firebase 存储中的单个 url:

`// Create a reference to the file you want to download 
let starsRef = storageRef.child("images/stars.jpg")
// Fetch the download URL starsRef.downloadURL { url, error in
if let error = error {
// Handle any errors }
else {
// Get the download URL for 'images/stars.jpg'
} }`

但是,我在那里有很多文件,那么我怎样才能跳过直接路径,而是遍历给定目录中的所有文件呢?

感谢提示。

最佳答案

DownloadURL 一次接受一个字符串。如果你想像我一样将文件夹中的所有文件显示到表格 View ,这里是完整代码:

   import UIKit import Firebase

我的第一个 View Controller -

   class FolderList: UIViewController {
var folderList: [StorageReference]?
lazy var storage = Storage.storage()

@IBOutlet weak var tableView : UITableView!

override func viewDidLoad() {
super.viewDidLoad()
self.storage.reference().child("TestFolder").listAll(completion: {
(result,error) in
print("result is \(result)")
self.folderList = result.items
DispatchQueue.main.async {
self.tableView.reloadData()
}
})
} }
extension FolderList : UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return folderList?.count ?? 0
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "FolderListCell", for:
indexPath) as? FolderListCell else {return UITableViewCell()}
cell.itemName.text = folderList?[indexPath.row].name
return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 64.0
} }

extension FolderList : UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
guard let downloadVC = storyBoard.instantiateViewController(withIdentifier:
"DownloadedItemView") as? DownloadedItemView else {
return
}
downloadVC.storageRef = folderList?[indexPath.row]
self.navigationController?.pushViewController(downloadVC, animated: true)
}
}

你每个细胞:

   class FolderListCell: UITableViewCell {

@IBOutlet weak var itemName : UILabel!

}

关于ios - 从 firebase 存储下载文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46832504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com