Download an image from Firebase to Flutter

3,336

You can just use the Storage API to download, like with upload

someMethod() async {
  var data = await FirebaseStorage.instance.ref().child("foo$rand.txt").getData();
  var text = new String.fromCharCodes(data);
  print(data);
}
Share:
3,336
user3217522
Author by

user3217522

Updated on December 03, 2022

Comments

  • user3217522
    user3217522 over 1 year

    There are many examples of uploading a file to firebase and getting a downloadUrl but there's no example that I found to get the DownloadURL for an image and using it in a Flutter widget.

    This is the one which is related to uploading a file

    final StorageReference ref =
        FirebaseStorage.instance.ref().child("foo$rand.txt");
    final StorageUploadTask uploadTask = ref.put(file);
    final Uri downloadUrl = (await uploadTask.future).downloadUrl;
    final http.Response downloadData = await http.get(downloadUrl);
    

    Can anyone give an example of one where the file already exists in firebase and how to get a download link?