BB Developer
BB Developer

Reputation: 374

Getting data from Firebase RTDB and Storage

I am using firebase for both hosting and data storage in an ecommerce site. Each product has text data that I store in the RTDB and images that I store in the Storage Bucket. Right now when I acess a product on the profile page, I have to make two calls, one to the RTDB and the other to the Storage Bucket. Is there a way I can make just one network call and retrieve both?

Thank you!

Upvotes: 0

Views: 237

Answers (1)

jered
jered

Reputation: 11581

No. The database and storage use separate APIs, there is no way to retrieve both with a single request. I'm not even sure how that would be possible for them to implement.

However there might be a workaround if you really, really need to do everything in a single API request. Since RTDB entires are strings, it's possible to encode and image as a base64 encoded string or data URI and save it to the database that way. Then when you access the RTDB you would decode the string back into an image. I believe there is a 10mb limit for each RTDB entry but that probably wouldn't be a problem. The bigger challenge is migrating all of your images from the storage bucket to the RTDB and rewriting your app to do everything through the RTDB without even touching the storage bucket.

Upvotes: 1

Related Questions