【问题标题】:How to download url file from firebase firestore flutter?如何从 firebase firestore flutter 下载 url 文件?
【发布时间】:2021-08-18 10:08:35
【问题描述】:

将 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;

}

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    假设您尝试下载的文件是公开可读的,如果不是,您可以阅读this documentation 以使其如此,您所要做的就是使用 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);
    });
    

    【讨论】:

    • 当我编码 query.forEach 时,forEach 是错误的。为什么?
    • forEach 得到了句子下面的红线
    • 但是错误信息是什么?你能把它编辑成你的问题吗?
    • 也许查询没有返回任何结果?尝试在 foreach 之前添加一个条件,例如:if(query.size() &gt; 0)
    • 嗯还是一样
    猜你喜欢
    • 2021-01-26
    • 2021-12-16
    • 2020-03-28
    • 2021-05-09
    • 2021-10-14
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    相关资源
    最近更新 更多