Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active June 27, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirawatee/0e4fc55cb5f09cae3a2f7f6892e07759 to your computer and use it in GitHub Desktop.
Save jirawatee/0e4fc55cb5f09cae3a2f7f6892e07759 to your computer and use it in GitHub Desktop.
Get file list from Cloud Storage
<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