title: How to delete a Firebase Storage file with flutter?
body: <p>I'm new to both Flutter and Firebase, so bear with me on this one.</p>
  <p>I am trying to delete a File in my Firebase Storage using the file Url.</p>
  <p>I have the full Url of the file and remove all characters excluding the file path.</p>
  <p>Then I try to delete the file. From following other answers on here I use the command;
  <code>FirebaseStorage.instance.ref().child(filePath).delete()</code></p>
  <p>Below is my code;</p>
  <pre><code>static void deleteFireBaseStorageItem(String fileUrl){
  
    String filePath = 'https://firebasestorage.googleapis.com/v0/b/dial-i-2345.appspot.com/o/default_images%2Fuser.png?alt=media&amp;token=c2ccceec-8d24-42fe-b5c0-c987733ac8ae'
                    .replaceAll(new 
                    RegExp(r'https://firebasestorage.googleapis.com/v0/b/dial-in-2345.appspot.com/o/'), '');
  
    FirebaseStorage.instance.ref().child(filePath).delete().then((_) =&gt; print('Successfully deleted $filePath storage item' ));
  
  }
  </code></pre>
  <p>The problem is the file never gets deleted.</p>
  <p>I think I have tracked down where the problem is.</p>
  <p>In the <code>.delete()</code> method there is a required 'app' and 'storageBucket' value.</p>
  <p>When I run this function the values are null.</p>
  <p><img src="https://i.stack.imgur.com/apkKd.png" alt="See screen shot" /></p>
  <p>I find this confusing because in the same file i see this;</p>
  <pre><code>/// The [FirebaseApp] instance to which this [FirebaseStorage] belongs.
  ///
  /// If null, the default [FirebaseApp] is used.
  final FirebaseApp app;
  
  /// The Google Cloud Storage bucket to which this [FirebaseStorage] belongs.
  ///
  /// If null, the storage bucket of the specified [FirebaseApp] is used.
  final String storageBucket;enter code here
  </code></pre>
  <p>From the documentation I can see maybe I need to use the 'Firebase core' plugin to make the app which links the bucket to that database. But there is not much specific to Dart &amp; flutter.</p>
  <p>Does anyone have any experience with this?</p>
  <h1>Found Temporary solution</h1>
  <p>So there is not a method to convert the Url to a storage reference at the moment. Hopefully it will come out in a Firebase update.</p>
  <p>Here was my hack</p>
  <pre><code> static void deleteFireBaseStorageItem(String fileUrl){
  
  String filePath = fileUrl
                    .replaceAll(new 
                    RegExp(r'https://firebasestorage.googleapis.com/v0/b/dial-in-2345.appspot.com/o/'), '');
  
  filePath = filePath.replaceAll(new RegExp(r'%2F'), '/');
  
  filePath = filePath.replaceAll(new RegExp(r'(\?alt).*'), '');
  
  StorageReference storageReferance = FirebaseStorage.instance.ref();
  
  storageReferance.child(filePath).delete().then((_) =&gt; print('Successfully deleted $filePath storage item' ));
  </code></pre>
  <p>}</p>
  <p>I know.... i know....</p>
  <p>Ps 'dial-in-2345.appspot.com' is relevant to my app and you would need to change it.</p>