Reputation: 1563
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 ?
Upvotes: 4
Views: 2701
Reputation: 1563
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();
Upvotes: 11