flutter - 如何从 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;
}
解决方案
假设您尝试下载的文件是公开可读的,如果不是,您可以阅读此文档以使其如此,您所要做的就是使用 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);
});
推荐阅读
- airflow - 在 GCP Composer 中运行命令
- json - JSON.parse 可能是编码问题的问题.... 超级奇怪
- python - 当在字段中输入按钮单击按钮时,Django UserCreationForm 没有响应
- python - 为什么 Exception 子类没有被 except 子句捕获?
- cordova - 更改 cordova-plugin-dialogs 的通知声音
- java - 如何在 JPanel 中更改三角形的边长?
- reactjs - 如何更新对象数组中具有相同名称的所有键?
- ios - iOS 是否会降低使用麦克风的应用程序的扬声器音量?
- python - 如何从嵌套字典创建多索引数据框?
- python - 如何修复此错误模块“django.http.request”没有属性“META”?