简体   繁体   中英

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.

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 , ie byte data, as well).

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM