i want to store my uploaded images urls to firestore as list
also im trying store multiple images for profile this is how i come to storing images if are there any better way to do that please let me know
await _firebaseFirestore.collection("noktalar").doc().set({
'aciklama': aciklama,
'lat': 123,
'long': 123,
'mailAdresi': mailAdresi,
'noktaAdi': noktaAdi,
'telefon': tel,
'webAdresi': webAdresi,
'yetkiliAdiSoyadi': yetkili,
'resimler': FieldValue.arrayUnion(resimler)
});
and i tried this also
'resimler': imagesUrls.map((value) => value.toJson()).toList(),
CodePudding user response:
You can basically store image URLs as a Strings and when you'll get them in code, you can just use split method to make list from String. That's pretty easy method to solve this problem
CodePudding user response:
You can follow the below steps:
- First upload your image to Firebase Storage and get the download URL.
- Now you have the download URL and you can Upload your Enter object to Cloud FireStore with the url.
You can use the below function to get the download url of uploaded image and then store them in a location in Firestore.
Future<String> uploadImage(var imageFile ) async {
StorageReference ref = storage.ref().child("/photo.jpg");
StorageUploadTask uploadTask = ref.putFile(imageFile);
var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
url = dowurl.toString();
return url;
}
You may also refer to the blog.