gpt4 book ai didi

swift - 在 Swift 4 中将图像上传到 Firebase 存储

转载 作者:行者123 更新时间:2023-11-28 07:46:07 24 4
gpt4 key购买 nike

我想为每张图片上传两份副本,一张全尺寸和一张缩略图。我在这里寻找关于 SO 和 Firebase 文档的答案。

使用下面的代码,只有缩略图图像被保存到存储中。我怎样才能修复它以便上传两个图像?显然我还没有完全理解如何处理返回/关闭。帮助非常感谢!

这一系列方法在用户点击上传按钮时被调用

self.uploadAndGetFullSizeImageDownloadURL(completion: { (url) in

print("Fullsize URL: \(url) is stored")
self.fullSizeDownloadURL = url

self.uploadAndGetThumbNailImageDownloadURL(completion: { (url) in
print("Thumbnail URL: \(url) is stored")
self.thumbNailDownloadURL = url

// Save image info to database
self.saveImageInfoToDatabase(fullSizeURL: self.fullSizeDownloadURL, thumbNailURL: self.thumbNailDownloadURL, completion: { (finished) in

...
})
})
})

上传和获取 URL 的方法如下所示:

func uploadAndGetFullSizeImageDownloadURL(completion: @escaping (String) -> Void) {

var fullUrlStr = ""

// Get imageData
let fullSizeImageData = self.getImageData(size: "fullSize")

// Upload fullsize image to storage
let fullSizeStorageRef = self.sRef.child("\(String(describing: uid!)), \(createdAt!)")
fullSizeStorageRef.putData(fullSizeImageData, metadata: nil, completion: {
(metadata, error) in

print("Fullsize image is stored")

// Get the fullsize downloadURL
fullSizeStorageRef.downloadURL(completion: { (url, error) in
if let downloadURL = url?.absoluteString {
fullUrlStr = downloadURL
//Return fullsize downloadURL
completion(fullUrlStr)
}
})
})
}

最佳答案

找到了一个方法: How to upload multiple image on firebase using swift?

这是一种不同的方法,但效果很好。

关于swift - 在 Swift 4 中将图像上传到 Firebase 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50986401/

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