-1

How can I download a file from firebase firestore after I push the url from firebase storage to firebase firestore? I try to display the list of audio file. But how to download the file from firestore?

Future<List<DocumentSnapshot>> getAudioFile() async {
Map<String, dynamic> audios = {
  "audio": audio,
};

var docRef = FirebaseFirestore.instance.collection("Audio");
QuerySnapshot query = await docRef.limit(10).get();
return query.docs;

}

Error when im using forEach enter image description here The output

fizahpanda103
  • 49
  • 2
  • 7

1 Answers1

0

Assuming the file you are trying to download is publicly readable, and if not you can read this documentation to make it so, all you have to is use the URL to download the file as follows:

var docRef = FirebaseFirestore.instance.collection("Audio");
QuerySnapshot query = await docRef.limit(10).get();
query.forEach((doc) async {
    // this variable will contain your downloaded file and you can build your code from here
    http.Response downloadData = await http.get(doc.url);
});
Ralemos
  • 5,571
  • 2
  • 9
  • 18