Check If A Folder Exists Of A Certain Name In Firebase Storage
Solution 1:
Cloud Storage for Firebase doesn't have event listners like Realtime Database. You're trying to do something that isn't supported (which is why you're getting a compiler error). Please see the API documentation for StorageReference to find out what you can do with that object.
On top of that, there is no way to check if a "folder" exists in Cloud Storage. Cloud Storage doesn't actually have any folders. It just has files with path components that look like folders.
If you want to know if a file exists (not a "folder"), then you could use the getMetadata method on a StorageReference that refers to the file.
Solution 2:
If the question was about checking whether a folder exists in a realtime firebase database using C#, then the answer is below:
You can use the json returned from the DataSnapshot, when searching for an item, to determine whether the directory exists or not. If the json is null, even though the value may not be, it doesn't exist (or is empty).
This can be done using DataSnapshot.GetRawJsonValue()
Here's an example:
My Firebase Database structure looks like this:
- Users
- Bob
- Name : "Bob"
- Age : 24
- Bob
Here's the full code of how to check if the value 'Bob' exists in the database or not:
stringjsonConfig="Text from the google-services.json file you get from the database";
AppOptionssettings= AppOptions.LoadFromJsonConfig(jsonConfig);
app = FirebaseApp.Create(settings);
FirebaseDatabasedatabase= FirebaseDatabase.GetInstance(app);
// Gets the folder 'Users'
database.GetReference("Users")
// Gets the child called 'Bob' (whether it exists or not)
.Child("Bob").GetValueAsync().ContinueWith(task =>
{
if (task.IsCompleted)
{
if (task.Result.GetRawJsonValue() == null)
{
// 'Bob' doesn't exist
}
else
{
// 'Bob' exists
}
}
});
Post a Comment for "Check If A Folder Exists Of A Certain Name In Firebase Storage"