Why use async function "getDownloadURL" to get file URL in Firebase Storage


kusumoto_teruya

In order to get the URL of the file uploaded to Cloud Storage, we have to write the following code.

import { getStorage, ref } from 'firebase/storage'

const storage = ref(getStorage(firebaseApp))
const url = await getDownloadURL(ref(storage, 'images/sample.jpg'))

Why do we need to call an async function instead of knowing the URL of the unique file from the start?
I guess the authentication is done when you call "getDownloadURL".
But if authentication is required, why not issue a unique URL for the file and then authenticate when that URL is called?

alex marmo

Why do we need to call an async function instead of knowing the URL of the unique file from the start?

This is because the download URL is generated on the server. This URL will be available as soon as the data is successfully uploaded to Firebase Storage. This is an asynchronous operation because it takes time to actually upload the data to the server. Depending on the connection speed and status, and the size of the data, the upload can take anywhere from a few hundred milliseconds to a few seconds to complete. Among other things, the URL contains a token that is automatically created whenever a file is uploaded to Cloud Storage. This is a random token, which makes the URL difficult to guess.

That's why you can't know the final download URL ahead of time. This is different from pushing IDs in Realtime Database or generating document IDs in Firestore, both of which are done on the client side.

Related


How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; } }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); c

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); c

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using firebase storage to store images into it, the images are easy to upload to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); co

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Get download URL of Firebase Storage file

birdcage I have a mobile app that requires Firebase registration to backup/restore custom user data in Firebase. I would like to know if an authorized user can somehow get the url of his own stored file and download it to his computer. Frank Vampfelen If a use

Firebase store getDownloadUrl is not a function

wabajoshi I'm developing a vue app with firebase, I've mentioned similar questions but didn't find any solution to my problem. What I want to do is store the download URL into my event database. my code: var stRef = st.ref(`event-photos/${eventId}`) // st is f

Token validity for Firebase Storage getDownloadUrl

Bumblebee I have a problem with the "token" in the url(&token=) when using FirebaseStorage's getDownloadUrl. https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456 It says to return a "long lived" d

Token validity for Firebase Storage getDownloadUrl

Bumblebee I have a problem with the "token" in the url(&token=) when using FirebaseStorage's getDownloadUrl. https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456 It says to return a "long lived" d

Token validity for Firebase Storage getDownloadUrl

Bumblebee I have a problem with the "token" in the url(&token=) when using FirebaseStorage's getDownloadUrl. https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456 It says to return a "long lived" d

Firebase Storage "getDownloadURL" returns undefined

Oy3 I am trying to add an image to firebase storage and use the image URL to add data to firestore. The image is uploading to firebase storage, but if I use the getDownloadUrl method, it doesn't return the URL. It returns this error: Uncaught TypeError: Cannot

Token validity for Firebase Storage getDownloadUrl

Bumblebee I have a problem with the "token" in the url(&token=) when using FirebaseStorage's getDownloadUrl. https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456 It says to return a "long lived" d

Token validity for Firebase Storage getDownloadUrl

Bumblebee I have a problem with the "token" in the url(&token=) when using FirebaseStorage's getDownloadUrl. https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456 It says to return a "long lived" d

Get URL of uploaded file in Firebase Storage using Vuejs

opportunity I have a small bug with my script, I try to upload a file to firebase storage using vuejs, everything works except the url is null, my script is a form of book value with id, titre, description, prix_d , pdf (is a file), pdf_url and the upload valu

Get URL of uploaded file in Firebase Storage using Vuejs

opportunity I have a small bug with my script, I try to upload a file to firebase storage using vuejs, everything works except the url is null, my script is a form of book value with id, titre, description, prix_d , pdf (is a file), pdf_url and the upload valu

Get URL of uploaded file in Firebase Storage using Vuejs

opportunity I have a small bug with my script, I try to upload a file to firebase storage using vuejs, everything works except the url is null, my script is a form of book value with id, titre, description, prix_d , pdf (is a file), pdf_url and the upload valu