Want to upload image to Firebase using Flutter? This worked for me… In my case, I also needed to get the download URL and push to a firestore collection. After doing some reading I found that it’s best to use a StorageTaskSnapshot and then get download URL.
1 2 3 4 5 6 7 8 9 10 11 |
uploadImage(File image) async { StorageReference reference = FirebaseStorage.instance.ref().child(image.path.toString()); StorageUploadTask uploadTask = reference.putFile(image); StorageTaskSnapshot downloadUrl = (await uploadTask.onComplete); String url = (await downloadUrl.ref.getDownloadURL()); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.