【发布时间】:2021-11-20 17:30:17
【问题描述】:
我正在使用以下内容从对 google firebase 存储桶文件列表的引用中检索前缀...但是当我 console.log 时,它们没有记录前缀。
我希望 console.log("PREFIXES" + foldeRef); 显示前缀,但 foldeRef 不返回它出现的任何内容。
const getNewImages = () => {
const listRef = storageRef
.child("users")
.child("H7pFwl0uuRV1NMt8y55S42hxpTi2");
// Find all the prefixes and items.
listRef
.listAll()
.then((res) => {
res.prefixes.forEach((foldeRef) => {
const PREFIX = foldeRef.listAll();
console.log("PREFIXES" + foldeRef);
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach((itemRef) => {
console.log("Items " + itemRef);
array.push(itemRef);
// All the items under listRef.
//console.log('ARRAY'+array);
//setTestImage(array);
//console.log("TEST IMAGE " + array);
});
})
.catch((error) => {
console.log("ERROR" + error);
// Uh-oh, an error occurred!
});
};
【问题讨论】:
-
itemRef 是否返回任何内容?你有任何错误吗?
-
itemRef 返回指向我的 Firebase 存储中图像的链接,即“gs://.....”,但在这种情况下,我没有使用它,只是将其放在那里以供参考。我也没有收到任何错误。实际上我刚才通过访问图像 URL.name 以不同的方式解决了这个问题,但我仍然很好奇为什么前缀没有被访问。
-
再次您好,抱歉回复晚了。但是在使用列为what firestore uses 的API 进行测试时,我注意到前缀数组的值实际上是其中包含的子文件夹,而不是完整的前缀/路径。因此,它似乎是为了进一步深入研究,而不是描述对文件的完整引用。我相信name 是你想要的。
-
是的,这就是我最终弄清楚的。我改为访问每个返回项目的 URL.name...感谢您的帮助!
-
抱歉,有时我的吸收速度有点慢,需要自己看一下才能意识到你在说什么。您介意发布您在答案中找到的解决方案并接受它吗? (出于知名度的原因)我会自己做,但这感觉就像是在无端夸奖。
标签: javascript firebase react-native google-cloud-platform google-cloud-firestore