2
votes

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 ?

1

1 Answers

10
votes

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();