无法从Firebase存储获取下载URL(所需的引用处没有对象.) [英] Failing to get a download URL from firebase storage(No object exists at the desired reference.)
问题描述
我一直在尝试获取Firebase存储中图像的下载URL,因此可以将其添加到列表视图构建器"NetworkCatched Images"中.对于列表中每个项目,您都可以从下面的代码中看到,我首先在有状态类的开头声明了一个变量,称为"URL".所以我可以通过使其值等于我从Firebase存储获得的下载URL来更改值,但似乎我正在使用的异步函数甚至没有运行,因为我确保它在打印完后会打印出下载URL的值它已经完成了,但是我在调试控制台中什么也没看到,这里哪里出了问题?
我不断收到此错误所需的引用处没有对象.
"thesnapshot.data()['image']"
等于图像文件的名称,例如 books.jpg
是文件的确切名称,它位于一个名为category的文件夹中,如下所示,非常感谢您的启发 class Home扩展State< HomeScreen>{var url;ListView.builder(shrinkWrap:true,填充:EdgeInsets.all(0),物理:NeverScrollableScrollPhysics(),itemCount:snapshot.data.documents.length,itemBuilder:(BuildContext context,int index){DocumentSnapshot thesnapshot = snapshot.data.docs [index];current_category = thesnapshot.data()['category'];printUrl()异步{参考ref = FirebaseStorage.instance.ref().child("category/" + thesnapshot.data()['image'].toString());var togo =(await ref.getDownloadURL()).toString();setState((){url =多哥;打印(URL);});}printUrl();
我认为您的引用中包含的.ref()和thesnapshot.data()['image'].toString().
尝试这样的事情
Future< void>downloadURLExample()异步{字符串downloadURL =等待firebase_storage.FirebaseStorage.instance.ref('users/123/avatar.jpg').getDownloadURL();
i have been trying to get the download URL for my images in firebase storage so I can add it to my listview builders "NetworkCatched Images" for each of my items in the list, as you can see from my code below, I first declared a variable at the beginning of my stateful class called "URL" so I could change the value by making it equal to the download URL i get from firebase storage, but it seems like the async function I'm using doesn't even run because i made sure it prints out the value of the downloaded URL after it is done, but i see nothing in my debug console, where am going wrong here?
i keep getting this error No object exists at the desired reference.
by the way, the "thesnapshot.data()['image']"
in my code is equal to the name of the image file e.g books.jpg
which is the exact name of the file and it is in a folder called category as you can see below, would really appreciate some enlightenment on this, thanks
class Home extends State<HomeScreen> {
var url;
ListView.builder(shrinkWrap: true, padding: EdgeInsets.all(0), physics: NeverScrollableScrollPhysics(), itemCount: snapshot.data.documents.length, itemBuilder: (BuildContext context, int index)
{
DocumentSnapshot thesnapshot = snapshot.data.docs[index];
current_category = thesnapshot.data()['category'];
printUrl() async {
Reference ref = FirebaseStorage.instance.ref().child("category/" + thesnapshot.data()['image'].toString());
var togo = (await ref.getDownloadURL()).toString();
setState(() {
url = togo;
print(url);
});
}
printUrl();
I think that the .ref() included in your reference doesn't go thereas well as the thesnapshot.data()['image'].toString().
Try something like this
Future<void> downloadURLExample() async {
String downloadURL = await firebase_storage.FirebaseStorage.instance
.ref('users/123/avatar.jpg')
.getDownloadURL();
Extracted from the documentation
这篇关于无法从Firebase存储获取下载URL(所需的引用处没有对象.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!