How to check if a file exists in Firebase repository?

When using a database, you can do snapshot.exists() to check if certain data exists. According to the docs, there is no such storage method.

https://firebase.google.com/docs/reference/js/firebase.storage.Reference

What is the correct way to check for a specific file in Firebase storage?

+6
source share
2 answers

I believe that the FB repository API is configured in such a way that the user requests only the file that exists.

Thus, a non-existent file should be treated as an error: https://firebase.google.com/docs/storage/web/handle-errors

+3
source

You can use getDownloadURL , which returns Promise , which, in turn, can be used to detect a "not found" error or process the file if it exists. For instance:

 storageRef.child("file.png").getDownloadURL().then(onResolve, onReject); function onResolve(foundURL) { //stuff } function onReject(error) { console.log(error.code); } 
+8
source

All Articles