如何下载Firebase存储文件

问题描述 投票:0回答:1

截至目前,我正在使用资产文件夹中的当前图像,这肯定会造成内存/应用大小问题。

我将照片上传到其相关存储参考中的Firebase存储,现在我对如何从此处从存储中下载每个图像有些困惑。

这是我当前的代码


// Trend Model

enum Gender { case male, female }

struct Trend {
    var name: String
    var details: String
    var image: UIImage?
    var gender : Gender
    var childValue: String
}

// Create trend
let femaleTrends = [

Trend(name: "Animal Prints", details: "Details will go here!", image: UIImage(named: "AnimalPrintW"), gender: .female, childValue: "animalprints"),

Trend(name: "Green", details: "Details will go here",image: UIImage(named: "Green"),gender: .female, childValue: "green")
]

 let maleTrends = [

Trend(name: "Animal Prints", details: "Details will go here!",image:UIImage(named: "AnimalPrintM"),gender: .male , childValue: "animalprints"),

....

]

这里是另一个视图控制器,其中包含一个显示趋势列表的集合视图

//Display the current trend image place holder and labels
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "homeViewCell", for: indexPath) as! CurrentTrendsCell

        switch selectedSegmentIndex {
        case 0: cell.trendsLabel.text = femaleTrends[indexPath.row].name
        cell.trendsImageView.image = femaleTrends[indexPath.row].image


        case 1: cell.trendsLabel.text = maleTrends[indexPath.row].name
        cell.trendsImageView.image = maleTrends[indexPath.row].image

        default: break

        }
        return cell


    }

我阅读了Firebase存储文档并尝试了一些练习代码

let animalPrintRef = STORAGE_FEMALETREND_IMAGES_REF.child("AnimalPrints.jpeg").getData(maxSize: 1) { (data, error) in
      if let error = error {
            // Uh-oh, an error occurred!
          } else {
            // AnimalPrints.jpeg" is returned

             // This is the image I need
             let image = UIImage(data: data!)

          }
}

我理解它,但是我不确定如何获取每个trend的图像数据并将其实现到image中的Trend中>

截至目前,我正在使用资产文件夹中当前的图像,这肯定会造成内存/应用大小问题。我将照片上传到了相关存储参考中的Firebase存储中...

ios swift firebase firebase-storage
1个回答
0
投票

使用Firebase存储来保存图像并将图像链接放入数据库。

© www.soinside.com 2019 - 2024. All rights reserved.