我正在嘗試建立一個網站來發展我的技能。我嘗試做某事,但找不到解決方案。
import { getStorage, ref, listAll } from "firebase/storage";
const storage = getStorage();
// Create a reference under which you want to list
const listRef = ref(storage, 'files/uid');
// Find all the prefixes and items.
listAll(listRef)
.then((res) => {
res.prefixes.forEach((folderRef) => {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach((itemRef) => {
// All the items under listRef.
});
}).catch((error) => {
// Uh-oh, an error occurred!
});
在 Firebase Storage 檔案中,我可以看到如何獲取所有前綴和檔案。我想要做的是從檔案夾中只獲取一項。有沒有辦法做到這一點?
uj5u.com熱心網友回復:
注意:listAll只檢索檔案名,而不是這些檔案中的資料。
無法通過 API 獲取檔案夾中只有一個檔案名的串列。我建議給第一個檔案一個默認名稱,default.jpg這樣您就可以在代碼中使用該名稱,或者只檢索第一個listAll給您的檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/421177.html
標籤:
