使用Swift处理Image Store到Firebase [英] Handling Image Store to Firebase with Swift

查看:145
本文介绍了使用Swift处理Image Store到Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我上传到Firebase的方式。但需要一段时间才能取回。

  if imagePathToUpload!= nil {
let uploadImgPath = Firebase(url:\(rootURL)/ users / \(id!))
let imageData = UIImagePNGRepresentation(image)
let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
let imageRef = uploadImgPath.childByAppendingPath(\(path!))
$ b $ dispatch_async(dispatch_get_main_queue(),{
imageRef.setValue(base64String)
})



$ b

图片大小为370x370,所以在我看来不应该这么长。或者我应该尝试缩小图像,然后再上传它?



处理图像存储到Firebase的正确方法是什么?

解决方案


处理图片存储到Firebase的正确方法是什么? $ b

由于涵盖在之前的许多问题中:Firebase JSON数据库不适合存储图像。处理用户生成图像的最佳方式是将其存储在专用的文件/图像存储服务上,然后将该服务的URL存储在Firebase数据库中。

/ p>

更新:在I / O 2016 Firebase中引入了,这是 ,非常适合存储图片。


This is how I upload to Firebase. But it takes a while to fetch it back. Also while saving it too, that's why I tried asynchronising the process.

if imagePathToUpload != nil {
   let uploadImgPath = Firebase(url:"\(rootURL)/users/\(id!)")
   let imageData = UIImagePNGRepresentation(image)
   let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
   let imageRef = uploadImgPath.childByAppendingPath("\(path!)")

    dispatch_async(dispatch_get_main_queue(), {
         imageRef.setValue(base64String)
    })
  }                

The image size is 370x370 so it shouldn't take that long in my opinion. or should I try to smaller the image before I upload it?

What is the proper way of handling image storage to Firebase?

解决方案

What is the proper way of handling image storage to Firebase?

As covered in many questions before: the Firebase JSON Database is not a good fit for storing images.

The best way to handle user-generated images is to store them on a dedicated files/image storage service and then store the URL of that service in your Firebase Database.

Update: At I/O 2016 Firebase introduced Firebase Storage, which is a perfect fit for storing images.

这篇关于使用Swift处理Image Store到Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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