映射 firebase 存储中的所有图像

Mapping through all images in firebase storage

我已经开始学习 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}/>
    </>
  );
}

谁能给我解释一下,如何映射所有图像?谢谢!

您可以使用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
    });
  })