2

I am trying to upload images to firebase along with other string and double data type.

I am think about 2 options now, one is uploading the imageUrl to firebase Realtime Database and when I retrieved it, I will retrieve a imageUrl and convert it to image.

Another way is to upload the image file to Firebase storage.

Which one is the preferred one to do? From the speed of loading image? or other factors that I haven't thought of.

Thank you for your help! I appreciate it.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jihang Liu
  • 353
  • 1
  • 5
  • 12
  • In addition to the two excellent answers already give, have a look at all of the options for storing data in Firebase here: https://stackoverflow.com/questions/37482907/firebase-differences-between-realtime-database-and-file-storage – Frank van Puffelen Jun 13 '18 at 03:14

5 Answers5

5

Don't store large binary objects in Realtime Database. Use Cloud Storage instead.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • How about store image url in Realtime Database? Since I don't really have any large objects? – Jihang Liu Jun 13 '18 at 21:44
  • You do have a large binary object - the image itself. It should be trivial to store a reference to its location in the database. – Doug Stevenson Jun 13 '18 at 21:46
  • My apology., I think I didn't state my question clear. I retrieved image from online by their url. If I only push these urls to my realtime Database, and retrieve them again later, is realtime Database a ideal subject to use? – Jihang Liu Jun 13 '18 at 21:53
  • If all you want to do is store a string URL, then that would go in a database. Cloud Storage isn't at all a good option for storing small strings. – Doug Stevenson Jun 13 '18 at 21:58
  • Thank you, I appreciate it. I don't really store anything besides simple strings and doubles. Is there any concern that I should be aware of if retrieving the image data by their urls? – Jihang Liu Jun 13 '18 at 22:00
  • Can you check this question please,https://stackoverflow.com/questions/57236615/how-to-save-object-of-images-to-real-time-firebase @DougStevenson – DevAS Jul 27 '19 at 23:09
2

Upload image urls is a better option. Upload the image is a heavier task, hence it is better to upload urls with other data.

Anirudh Bagri
  • 2,346
  • 1
  • 21
  • 33
1

It depends on how big your app is going to scale. However, storing a large binary files in real time database is not a good practise. I would suggest you to use cloud storage, usually AWS buckets to store images and save the URL to firebase, to retrieve it later.

toxdes
  • 421
  • 4
  • 8
  • Ideally, I am not going to store any images. But only the image url that I retrieved from online before. And I want to load them later. In this case, is image url in realtime database a better idea? – Jihang Liu Jun 13 '18 at 21:50
  • In that case, you are just storing the strings of URLs and it's perfectly fine to use real-time database – toxdes Jun 15 '18 at 04:33
1

Storage is given from firebase to store all your large data and then fetch asynchronously. So using storage should be a better way rather than database.

Basir Alam
  • 1,332
  • 20
  • 24
1

For any kind of file you must have to use storage, and then store only file name in your realtime database to maintain good performance of your application. And that is the main reason firebase provide those functionalities in separate ways.

Dhaval Dobariya
  • 475
  • 4
  • 9
  • How about store image url in Realtime Database? I only have image as big files, others are just strings and double. So I am thinking to send image url to database together. Is there any concern that I should be aware of if I use image url? – Jihang Liu Jun 13 '18 at 21:48
  • Yes, you can also store image URL in realtime database , so you can directly use that without writing any string appending code to create your desired image URL. – Dhaval Dobariya Jun 14 '18 at 01:01