0

I have an app onto Firebase when users can register themselves and have to be also able to upload an image/avatar onto the backend.

In the first place I wanted to stick to something like Amazon S3, but then I thought it would have been better keeping simple.

So.. for not-large scaled apps, can it be considered a good practice storing images in a sub JSON Tree?

By good practice I mean:

  • It won't hurt drammatically query performances
  • It would be recommended by experts programmers with experience in NoSQL dbs
  • It won't hurt other json trees query performances

I wonder about this because I know that storing files is discouraged in dbs, and NoSQL dbs can furtherly suffer in performances.

I was thinking to store images in a sub json tree like /avatars, where the key/value pair should be:

-user1_uid: image_base64...

-user2_uid: image_2...

-....

Where the image value is a Base64 string of the image, so can converted back to a file.

The images would be so fetched:

I get the uid key of the user I want to fetch the image of.

I query the image value from myapp.io/avatars/userX_uid (server side filtering)

I use the image.

So... can it be defined a good practice?

Thanks in advice

EDIT: I'm now thinking also about image caching... How should I cache these images after fetching them? Since it's not about simple urls anymore I should have to do this manually..

BlackBox
  • 631
  • 1
  • 5
  • 19
  • 1
    Storing images in firebase is not considered good practice. Take a look at [this answer](http://stackoverflow.com/questions/35076473/how-do-you-save-a-file-to-a-firebase-hosting-folder-location-for-images-through/35076653#35076653) – André Kool May 14 '16 at 11:50
  • Thanks. I read it. Now I wonder which service is easy to use and with a good free plan.. Not asking for the best, just for a good one – BlackBox May 14 '16 at 13:11
  • Possible duplicate of [How can I view and store images in firebase?](http://stackoverflow.com/questions/13955813/how-can-i-view-and-store-images-in-firebase) – Jay May 14 '16 at 13:15
  • There's a *lot* of discussions on Stackoverflow about storing images in Firebase, options, providers etc so you may just want to search and read through past suggestions. – Jay May 14 '16 at 13:16
  • @Jay, well he asks if it's possible. I know it is possible but asked if it should be done, in terms of efficiency and convenience... I read many posts about it but didn't find something much helpful. But a curiosity: If I store images (not really large) in a separate subtree for images, does it slow down the whole json tree when making queryies? – BlackBox May 14 '16 at 13:30
  • My point is: If I use Firebase for storing avatars in an attempt to do it efficiently (so not storing images in user recirds), will it in the future provokate issues with my app? Assuming there won't be more than 100 users with avatars, or in the long time not more than 1000 for sure – BlackBox May 14 '16 at 13:35
  • @BlackBox The OP question 'Is it good practice' and the general answer would be no. Can it be done? Certainly, see my answer here [Retrieving Images From Firebase](http://stackoverflow.com/questions/33644560/swift2-retrieving-images-from-firebase/34044446#34044446). It really boils down to the size of the image. The OP didn't specify a file size so it's hard to answer. If it's truly just avatars, 160x160 for example, that's pretty small and is ok. Higher quality ones that are a lot larger in size should be stored using another web service and keep a link to those in Firebase is the way to go. – Jay May 14 '16 at 13:56
  • @BlackBox and to answer the question; Firebase doesn't care where data is stored so the location of images will not affect performance; as to Firebase, images are just a serial of text characters. They can be stored with /users/user data or in a separate node. What does matter is the structure in which they are stored; the flatter the structure the better. See [Denormalizing Data Is Normal](https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html) – Jay May 14 '16 at 14:01
  • So it would be just a question of schemes and not of performance? – BlackBox May 14 '16 at 14:11

0 Answers0