将图像从Firebase下载到Flutter
问题内容:
有很多将文件上传到firebase并获得downloadUrl的示例,但是我没有找到获取图像的DownloadURL并在Flutter小部件中使用它的示例。
这与上传文件有关
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中文件已存在的地方以及如何获得下载链接?
问题答案:
您可以使用Storage API进行下载,就像上传一样
someMethod() async {
var data = await FirebaseStorage.instance.ref().child("foo$rand.txt").getData();
var text = new String.fromCharCodes(data);
print(data);
}