Milos Pavic
 · Freelancer

IF google storage image exist dele it -- cant access AuthenticatedUser.photo_url

Resolved

i have nice action who is working properly, but i can't pass AuthenticatedUser.photo_url it is disabled in app.

How can i solve this, it seems that only image component can read AuthenticatedUser.photo_url.

Future deleteImageIfExist(String? imagePath) async {
  // validate if file exist at google storage url
  if (imagePath == null) {
    return;
  }

  if (imagePath.startsWith('gs://') || imagePath.startsWith('https://')) {
    final storage = FirebaseStorage.instance;
    final ref = storage.refFromURL(imagePath);

    try {
      final metadata = await ref.getMetadata();
      if (metadata != null) {
        await ref.delete();
      }
    } catch (e) {
      print('Error deleting image: $e');
    }
  } else {
    return;
  }
}
3 replies