Skip to content

Instantly share code, notes, and snippets.

@anoochit
Created December 17, 2022 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoochit/ab347ce9895d8795d4839ca58b6f8673 to your computer and use it in GitHub Desktop.
Save anoochit/ab347ce9895d8795d4839ca58b6f8673 to your computer and use it in GitHub Desktop.
How you can store an image in Cloud Firestore using Flutter
dependencies:
cloud_firestore: ^0.14.0+2
firebase_storage: ^4.0.0
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