Reputation: 397
const url = await firebase
.storage()
.ref('users/1/profile.png')
.getDownloadURL()
const url = await firebase
.storage()
.refFromURL(invalidURL)
.getDownloadURL()
const url = await firebase
.storage()
.ref(`users/${user.id}/${user.image}`)
.getDownloadURL()
Upvotes: 0
Views: 581
Reputation: 26333
The download URL and the reference path are two different things and I'd store each of them as appropriate (and sometimes both).
Store the Download URL when you want to directly serve the file from storage (e.g. an <img>
tag).
Store the Reference Path when you need to keep a reference to the file to modify it later.
Calling getDownloadURL()
does trigger a network request and so it's advisable to cache the result when possible to avoid unnecessary extra work/latency.
Upvotes: 2