senty
senty

Reputation: 12857

Handling Image Store to Firebase with Swift

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?

Upvotes: 1

Views: 1784

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599956

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.

Upvotes: 3

Related Questions