Skip to content

Instantly share code, notes, and snippets.

@bcnzer
Created February 9, 2020 09:41
Show Gist options
  • Save bcnzer/e36462c8afad11e95af6dff1502faba9 to your computer and use it in GitHub Desktop.
Save bcnzer/e36462c8afad11e95af6dff1502faba9 to your computer and use it in GitHub Desktop.
Example of using the getDownloadURL method to check for a file's existance
// Using promise
const listRef = storage
.ref('screenshots/abc123.png')
.getDownloadURL()
.then((response) => {
// Found it. Do whatever
})
.catch((err) => {
// Didn't exist... or some other error
})
// Using async/await
const ref = storageRef.ref('screenshots/abc123.png')
try {
await ref.getDownloadURL()
// Do whatever
} catch(err) {
// Doesn't exist... or potentially some other error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment