Skip to content
Advertisement

Firebase Storage – Web v9 – how to check if file exists in bucket?

Currently I’m using getDownloadURL() and error handling like this

const storage = getStorage();

async checkIfFileExists(filePath) {
        const docRef = ref(storage, filePath)
        try {
            await getDownloadURL(docRef)
            return true
        } catch (error) {
            return false
        }
    }

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement