Currently I’m using getDownloadURL()
and error handling like this
JavaScript
x
12
12
1
const storage = getStorage();
2
3
async checkIfFileExists(filePath) {
4
const docRef = ref(storage, filePath)
5
try {
6
await getDownloadURL(docRef)
7
return true
8
} catch (error) {
9
return false
10
}
11
}
12
which works, but kind of feels like a workaround. So I’m wondering if this is the way to go or if there’s a better alternative. Maybe I’m missing a build in way to directly request the existence? (with ‘Web v9’ options)
Advertisement
Answer
There isn’t any direct way like exists()
to check existence of a file. The V9 SDK just has a new API surface designed to facilitate tree-shaking but most of the functionality remains same.