Created
December 17, 2022 03:37
-
-
Save anoochit/ab347ce9895d8795d4839ca58b6f8673 to your computer and use it in GitHub Desktop.
How you can store an image in Cloud Firestore using Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies: | |
cloud_firestore: ^0.14.0+2 | |
firebase_storage: ^4.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import 'package:firebase_storage/firebase_storage.dart'; | |
String filePath = 'images/my_image.jpg'; | |
File imageFile = File(filePath); | |
StorageReference storageRef = FirebaseStorage.instance.ref().child(filePath); | |
StorageUploadTask uploadTask = storageRef.putFile(imageFile); | |
// Wait for the upload to complete | |
await uploadTask.onComplete; | |
// Get the URL for the uploaded image | |
String imageUrl = await storageRef.getDownloadURL(); | |
await Firestore.instance.collection('images').add({ | |
'url': imageUrl | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment