Last active
June 27, 2020 10:27
-
-
Save jirawatee/0e4fc55cb5f09cae3a2f7f6892e07759 to your computer and use it in GitHub Desktop.
Get file list from Cloud Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
async function getImageList(profile) { | |
// Define reference path in Cloud Storage for Firebase | |
const storage = firebase.storage() | |
const storageRef = storage.ref() | |
const listRef = storageRef.child(`photos/${profile.userId}/thumbs`) | |
// Get file list | |
let listImage = await listRef.listAll() | |
// Check empty item | |
if (listImage.items.length == 0) { | |
document.getElementById("ul").innerHTML = `You don't have any images. Please upload photos via chatbot and try again.` | |
return | |
} | |
// loop to display images | |
let i = 1 | |
listImage.items.forEach(async itemRef => { | |
let thumbUrl = await itemRef.getDownloadURL() | |
document.getElementById("ul").insertAdjacentHTML( | |
'beforeend', | |
`<li><img src="${thumbUrl}" onclick="shareMsg(${i}, '${thumbUrl}')">${i}</li>` | |
) | |
i++ | |
}) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment