Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I upload images to Cloud Firestore or Firebase Storage?

Might be silly question but need to clear for beginner as like me.

I know how to upload image on Firestore database but I thought instead of use FirebaseStorage why we are not using base64 string for upload image, it might be so easy? Or there is some limitation on string length?

~ PS : I haven't tried with base64 string to upload image on Firestore.

like image 405
Govaadiyo Avatar asked Jul 01 '19 05:07

Govaadiyo


People also ask

Should I use firestore or Firebase?

Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.

Is Firebase good for storing images?

Update (20160519): Firebase just released a new feature called Firebase Storage. This allows you to upload images and other non-JSON data to a dedicated storage service. We highly recommend that you use this for storing images, instead of storing them as base64 encoded data in the JSON database.

What is the difference between cloud firestore and Cloud Storage?

Cloud Datastore automatically scales as you need it and supports transactions as well as robust, SQL-like queries. What is Cloud Firestore? NoSQL database built for global apps. Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps - at global scale.

Which method can we use to upload an image to Firebase Cloud Storage?

To upload a file to Cloud Storage, you first create a reference to the full path of the file, including the file name. Once you've created an appropriate reference, you then call the putBytes() , putFile() , or putStream() method to upload the file to Cloud Storage.

How to handle errors during uploading files to cloud storage for Firebase?

After a successful upload, we can fetch the download URL of the uploaded image and then fetch it with any image loader, e.g. Kingfisher. There could be errors during uploading files to Cloud Storage for Firebase at both server and client sides. We can handle the errors with the observe function.

How many Firebase Cloud Functions to resize image on FireStore create?

Cloud Firestore collection count 5 Firebase Cloud Function to resize image on firestore create 0 How to upload an array of images URLs to Firestore? 2 Why aren't my Firebase Storage URLs uploading to Google Cloud Firestore? 0 FIrebase Cloud Functions (Delete Firestore Document)

What is iCloud storage for Firebase?

Cloud Storage for Firebase is a cloud tool for developers to store files and fetch them at the client-side with the help of a user-friendly SDK. The SDK uses a singleton pattern to tackle the UIViewController lifecycle issue. The uploading task can continue even when the UIViewController is dismissed.

Is it possible to download an image from FireStore?

An image could easily exceed that. Firestore is not a good tool to store large amount of binary data. It would probably be better to store the image in Cloud Storage, then store the path to that image in Firestore so you can search for it and download it later.


3 Answers

The Cloud Firestore "Usage and limits" documentation states that the "Maximum size for a document" is 1 MiB (1,048,576 bytes).
This is a small amount of data for images and will only allow to store low resolution images in single documents. You could store images across multiple documents as a workaround, however, that is unnecessarily complicated and Firebase Storage solves this issue perfectly.

Additionally, you will be downloading the whole image (whole document) when listening to any change in a document. If you have a document that has an image (base64 string) and a likes (int count) field and you try to listen for real time updates of the likes, you will be downloading the full image every time client side.

Firebase Storage is therefore most likely what you are searching for as you can store objects of any size (as large as your capacity), it provides you with download URL's, and you do not have to handle any encoding or decoding (although Cloud Firestore allows blob's, i.e. byte data, as well).

like image 70
creativecreatorormaybenot Avatar answered Oct 21 '22 12:10

creativecreatorormaybenot


There are no benefits for storing files (as binary data) on Firestore, over Firebase Storage.

Firestore is billed mostly for reads writes and deletes, with a monthly free storage of only 1 GB !!! This can be a serious pitfall if not done right. Read How we spent 30k USD in Firebase in less than 72 hours.

Firebase Storage is by far the best option to store files, with nearly no file size limitation and with much cheaper prices, then simply save the files url's to Firestore and you are done.

like image 41
RonTLV Avatar answered Oct 21 '22 11:10

RonTLV


From the technical perspective, yes you can always store (base64) string and use it later to retrieve the image. However, base64 string is up to 30% higher than the bytes data. So, you'll loose the performance as well as storage if you use base64.

Secondly, using FirebaseStorage has another advantage. It is to upload the image when the mobile app is in the background. We, as a developer, don't have to write any specific code for this.

Limits of Cloud Firestore and Firebase Storage were already pointed out by @creativecreatorormaybenot.

My conclusion: Prefer Firebase Storage over base64.

like image 22
Sukhi Avatar answered Oct 21 '22 13:10

Sukhi