【发布时间】:2020-09-01 18:43:05
【问题描述】:
所以我有一个应用程序,用户可以在其中向地图添加注释,并且我希望每个用户都可以看到和访问这些创建的注释。我正在尝试将注释数据写入 Firestore,但似乎不支持图像。我还尝试将图像转换为 base64EncodedString,但随后文档超出了 1mb 的大小限制。 (通常为 10 mb 左右)。这是我的代码:
let strBase64UserPickedImage = image?.pngData()?.base64EncodedString()
let strBase64DefaultImage = UIImage(named: "Image-1")?.pngData()?.base64EncodedString()
// User gave both 'warnings' and 'image' values
if warnings != nil && image != nil {
db.collection("jumpSpotAnnotations").addDocument(data: [
"title": title,
"coordinate": coords,
"estimatedHeight": estimatedHeight,
"locationDescription": locationDescription,
"warnings": warnings!,
"image": strBase64UserPickedImage!
]) { (error) in
if let e = error {
print("There was an issue saving data to firestore: \(e)")
} else {
print("Successfully saved data.")
}
}
}
“if”语句还有更多部分,但它们无关紧要。如何在不超过大小限制的情况下保存图像?如果使用 Firestore 保存图像实际上是不可能的,那么 Firebase 是否有另一种方法?请记住,我正在努力使每个用户都可以访问这些注释,无论它是由谁创建的,我并不是要设置 userDefault 或任何东西。感谢您的帮助!
【问题讨论】:
标签: ios swift firebase google-cloud-firestore uiimage