从Firebase下载图像到Flutter [英] Download an image from Firebase to Flutter
本文介绍了从Firebase下载图像到Flutter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有很多例子可以将文件上传到firebase并获取downloadUrl,但是我没有找到一个示例来获取图片的DownloadURL并在Flutter小部件中使用它。
There are many examples of uploading a file to firebase and getting a downloadUrl but there's no example that I found to get the DownloadURL for an image and using it in a Flutter widget.
这是与上传文件有关的一个
This is the one which is related to uploading a file
final StorageReference ref =
FirebaseStorage.instance.ref().child("foo$rand.txt");
final StorageUploadTask uploadTask = ref.put(file);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
final http.Response downloadData = await http.get(downloadUrl);
任何人都可以举例说明firebase中已存在的文件以及如何获取下载链接?
Can anyone give an example of one where the file already exists in firebase and how to get a download link?
推荐答案
您可以使用Storage API下载,例如上传
You can just use the Storage API to download, like with upload
someMethod() async {
var data = await FirebaseStorage.instance.ref().child("foo$rand.txt").getData();
var text = new String.fromCharCodes(data);
print(data);
}
这篇关于从Firebase下载图像到Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文