Ad

Firebase - How To Attach Image's DownloadUrl To Its Own Metadata?

When we upload an image to the firebase storage, is there a way to attach that image's download url to its own metadata? From my understanding, it seems that you can only get the download url after you have called the:

ref.putBytes(byteArray, metadata);

So effectively, you can't have the downloadUrl until you have uploaded your image. And since your metadata is attached at the time when you upload your image, there doesn't seem to be a way to have your downloadUrl included in your metadata.

Please let me know if there's a way around this.

Why I want to attach downloadUrl to my metadata Just a bit of extra context. I want to have my downloadUrl attached to my image's metadata, so that I will be able to use the cloud function to pass these informations to the firebase database. I want to do it this way instead of uploading the downloadUrl to the firebase storage separately, so that I can ensure that the storage and database are always synced up. We can't have a situation where only the image was uploaded, or only the downloadUrl was uploaded.

Ad

Answer

You can update the metadata for a storage reference at any time by calling StorageReference.updateMetadata on it.

Ad
source: stackoverflow.com
Ad