How can I check if the Firebase Storage directory already exists in Flutter?
CodePudding user response:
There is no way to check if a "folder" exists in Cloud Storage.
This might sound strange, but you have to consider that folders don't actually exist in a bucket-based storage. Cloud Storage doesn't actually have any folders.
The files in the storage just have path metadata associated with them, so that we humans can think hierarchically like we do with folders.
If you want to know if a file exists (not a "folder"), then in your code you could await getMetadata();
on a StorageReference
that refers to the file you're looking for.
A workaround could be to create a dummy file such as "readme.md" inside each folder; that would certify its existence. If you can't find such file, your folder doesn't exist.
CodePudding user response:
firebase.database().ref("path/node/").on('value', (snapshot) => { console.log(snapshot.exists()); });