How to await the upload of file to Firebase Storage in Flutter?

1,928

I eventually figured out the solution, it's mentioned here: Flutter: Get FirebaseStorage Download URL & Upload Status

As answered by https://stackoverflow.com/users/6618622/copsonroad

we can use this:

StorageUploadTask uploadTask = ref.putFile(avatarImageFile);
StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
String downloadUrl = await storageTaskSnapshot.ref.getDownloadURL();
Share:
1,928
Ayush Shekhar
Author by

Ayush Shekhar

Ping me for anything flutter.

Updated on December 08, 2022

Comments

  • Ayush Shekhar
    Ayush Shekhar over 1 year

    I am trying to upload an image to Firebase Storage in Flutter, using the following code.

    StorageReference reference =
        FirebaseStorage.instance.ref().child("$fileId.jpg");
    StorageUploadTask uploadTask = reference.putFile(_imageFile);
    

    This does seem to work. But I need to find a way, to await this upload process. How can I go about it, given that reference.putFile(file) doesn't return a future ?