Estoy desarrollando una página y estoy usando Firebase Storage como almacenamiento de archivos. Intenté usar los códigos proporcionados en los documentos para desarrolladores de Firebase, pero parece que no puedo hacerlo funcionar. ¿Cual podría ser el problema?
document.getElementById("but").addEventListener('click', e => { // Create a reference under which you want to list const listRef = ref(storage, 'folder/'); // 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. console.log( getDownloadURL(ref(storage, `folder/${itemRef}`))) }) }) });No estoy seguro de qué problema tienes con el código, pero hay un error en:
res.items.forEach((itemRef) => { // All the items under listRef. console.log( getDownloadURL(ref(storage, `folder/${itemRef}`))) }) La función getDownloadURL realiza una llamada asíncrona al servidor, por lo que deberá usar await o then para capturar ese resultado:
res.items.forEach((itemRef) => { getDownloadURL(ref(storage, `folder/${itemRef}`)) .then((downloadURL) => { console.log(downloadURL); }); })