我已經開始學習 firebase,所以我需要映射和顯示我存盤中的所有影像。我知道如何下載并只顯示一張圖片及其路徑
const fireBaseApp = initializeApp(firebaseConfig);
function App() {
const [url, setUrl] = useState();
useEffect(() => {
const func = async () => {
const storage = getStorage(fireBaseApp);
const download = ref(storage, "logo.png");
await getDownloadURL(download).then((x) => {
setUrl(x);
});
};
func();
}, []);
return(
<>
<img src={url}/>
</>
);
}
那么有人可以解釋一下,如何映射所有影像嗎?謝謝 !
uj5u.com熱心網友回復:
您可以使用listAll()函式列出目錄或路徑中的所有檔案。
import { getStorage, ref, listAll } from "firebase/storage";
const storage = getStorage();
// Create a reference under which you want to list
const listRef = ref(storage, '/'); // replace path if needed
listAll(listRef)
.then((res) => {
res.items.forEach((itemRef) => {
// All the items under listRef.
// Can get download URL for each item here
});
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450873.html
標籤:javascript 反应 火力基地 网络 firebase-存储
上一篇:Firebase云存盤定價混亂
