Hi all,
I'm just looking at the URLs produced by Firebase Storage and wonder if there are some shortcuts I can take, or if I shouldn't rely on them and instead use the `downloadURL` instead.
Let's take a look at an `uploadTask.snapshot.downloadURL`:
*
https://firebasestorage.googleapis.com/v0/b/imagelicious-cc412.appspot.com/o/img%2F-KN9TykLgducJLnMNvIP?alt=media&token=12543652-05cf-415e-9ee9-cbbcb14770c4Currently, I'm storing this so I can use it, however, as you can see, it is stored at the prefix 'img/' + a .push() ref. So, if I have the image id such as '-KN9TykLgducJLnMNvIP' in this case, I can construct the URL from the component parts:
```
let img_id = '-KN9TykLgducJLnMNvIP'
let url = '
https://firebasestorage.googleapis.com/v0/b/imagelicious-cc412.appspot.com/o/img%2F' + img_id + '?alt=media'
```
This works because it seems that I don't need the token to actually get the image. However, I realised that I do need to add the `alt=media`, otherwise I just get some JSON metadata. So I have just a few questions on doing this:
1. is this something that is stable and I can presume the `uploadTask.snapshot.downloadURL` will always be of this format? Or should I not do this and instead always store the downloadURL in the database for use later on?
2. What is the `token` for in the `downloadURL` parameter and is it safe (or okay) to leave it off?
3. If I need to use the aforementioned `downloadURL`, I can store it after upload. Can I assume this will also never change, or do I need to get a new `downloadURL` at some point in the future?
4. Presuming I have to store the `downloadURL` and for the sake of security (that someone doesn't upload a different URL), I guess I should use some kind of validation rule such as: `".validate": "newData.isString() && newData.val().beginsWith('
https://firebasestorage.googleapis.com/v0/b/imagelicious-cc412.appspot.com/o/img%2F')"` or is there a better way to do this? That's the only way I have thought so far, but there may be something better.
Note: all of this is essentially so I can do fewer lookups and/or queries to the database and/or storage. My use-case is being able to view an image publicly (ie. un-auth'd) with a URL such as
https://example.org/#img/'-KN9TykLgducJLnMNvIPApologies for the in-depth queries and many thanks in advance for your help.
Cheers,
Andy