checkIfFileExists static method

Future<bool> checkIfFileExists(
  1. String path
)

Checks if a file exists in Firebase Storage.

  • path: The full storage path of the file.

Returns true if the file exists, false otherwise.

Implementation

static Future<bool> checkIfFileExists(String path) async {
  try {
    await _storage.ref(path).getDownloadURL();
    return true; // File exists if the download URL is retrievable
  } on FirebaseException catch (e) {
    if (e.code == 'object-not-found') {
      return false; // File does not exist
    }
    debugPrint("Error checking file existence: $e");
    return false;
  }
}