For example I have Firestore object with images, how should I store the images?
Should i store array of string(urls) or array of reference to Firebase Storage (not sure if it possible, maybe reference as string)?
It feels like storing a reference is more flexible, for example we can create reference before the image is uploaded and we not depend on the url , but I wonder if it will be correct decision.
By "storage reference" I'll assume you mean the path to the image in your storage bucket. Let's quickly define all three parts in play here:
StorageReference to it, and have permission to read/write the file. From a reference to a file, you can get the download URL and the path to that file.You can store #1 and/or #2 in a database, but you can't store #3 as references only exist in your application code.
Most commonly you'll see the download URL being shared, as that is the most familiar way to share files with others. And from the download URL, you can always create a reference, and thus also get the path.
You can also just store the path of the file, and then get the download URL as needed. This is slightly less common, as it requires that all users have full read access to the storage bucket, which isn't needed if you share download URLs directly.
I occasionally store both the path and the download URL for the image, to that both are loaded in one go. While either one can easily be mapped to the other, storing both removes the need for that mapping and keeps my code simpler. From how I phrase things I hope it's clear that this is a personal preference.
It depends on your implementation.
Note : Reference is more secure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With