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 ?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With