首页 > 解决方案 > 如何从 firebase firestore flutter 下载 url 文件?

问题描述

将url从firebase存储推送到firebase firestore后,如何从firebase firestore下载文件?我尝试显示音频文件列表。但是如何从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;

}

我使用 forEach 时出错 在此处输入图像描述 输出

标签: fluttergoogle-cloud-firestore

解决方案


假设您尝试下载的文件是公开可读的,如果不是,您可以阅读此文档以使其如此,您所要做的就是使用 URL 下载文件,如下所示:

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);
});

推荐阅读